all repos — kushiyaki @ abc51122ede2ab7e1bdbee1d9c229dd28234cb5e

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

feat: jsx to hast converter function
trickyni trickyniv56@gmail.com
Thu, 30 Apr 2026 13:38:43 +0300
commit

abc51122ede2ab7e1bdbee1d9c229dd28234cb5e

parent

0ce9861827fe2080a14ba3ead98458dbd91b78c5

2 files changed, 25 insertions(+), 0 deletions(-)

jump to
A .gitignore

@@ -0,0 +1,5 @@

+input +out +__TODO.md +design-document.md +node_modules
A writeComponent.js

@@ -0,0 +1,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"));