all repos — kushiyaki @ dfdf1b2314a9c2ad95d33bad5285c3b557b3f82f

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

feat: writePage processes MD as fragment
trickyni trickyniv56@gmail.com
Thu, 30 Apr 2026 16:35:38 +0300
commit

dfdf1b2314a9c2ad95d33bad5285c3b557b3f82f

parent

52915bea72a952b70019b646a7c4aaf1addea3ab

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

jump to
M .gitignore.gitignore

@@ -3,3 +3,4 @@ out

__TODO.md design-document.md node_modules +writePage.js
A writePageMain.js

@@ -0,0 +1,31 @@

+import { readFile } from "fs-extra"; +import { unified } from "unified"; +import remarkParse from "remark-parse"; +import remarkRehype from "remark-rehype"; +import rehypeStringify from "rehype-stringify"; +import remarkFrontmatter from "remark-frontmatter"; +import rehypeFormat from "rehype-format"; +import rehypeRaw from "rehype-raw"; +import rehypeWrap from "rehype-wrap"; +// +//NOTE input: markdown -> MDAST -> HAST -> HTML +//TODO does not yet accept before/after JSX components. +//This is using unified's rehypeDocument to create a boilerplate with a few +//inserts (favicon, css, title) +// + +export async function writePageMain(filepath) { + const processor = await unified() + .use(remarkParse) + .use(remarkFrontmatter) + .use(remarkRehype, { allowDangerousHtml: true }) + .use(rehypeRaw) + .use(rehypeWrap, { wrapper: "main" }) + .use(rehypeFormat) + .use(rehypeStringify) + .process(await readFile(filepath, "utf-8")); + return processor.value; +} + +// let input = "./input/content/cookie.md"; +// console.log(await writePageMain(input));