all repos — kushiyaki @ abc51122ede2ab7e1bdbee1d9c229dd28234cb5e

🍢 A tiny static site generator for grilling markdown files to perfection

writeComponent.js (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
import { unified } from "unified";
import rehypeStringify from "rehype-stringify";
import rehypeFormat from "rehype-format";
import rehypeParse from "rehype-parse";
import rehypeRaw from "rehype-raw";

export async function writeComponent(componentName, data) {
  const fn = await import(`./input/templates/${componentName}.jsx`);
  const jsxProcessor = unified()
    .use(rehypeParse, { fragment: true })
    .use(rehypeRaw)
    .use(rehypeFormat)
    .use(rehypeStringify);

  return await jsxProcessor.stringify(await jsxProcessor.run(fn.default(data)));
  // return await jsxProcessor.run(fn.default(data));
}

// console.log(await writeComponent("h2", { title: "blah" }));
// console.log(await writeComponent("home"));