all repos — kushiyaki @ dd2208a3ddbe119a993f866f53c8cb29fe881dc8

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

fix: more correct writeComponent calls
trickyni trickyniv56@gmail.com
Tue, 05 May 2026 15:08:42 +0300
commit

dd2208a3ddbe119a993f866f53c8cb29fe881dc8

parent

9295af41432fa98494bf86bf65860235711d86b5

2 files changed, 19 insertions(+), 23 deletions(-)

jump to
M extractFrontmatter.jsextractFrontmatter.js

@@ -1,3 +1,4 @@

+import { readFile } from "fs-extra"; import { unified } from "unified"; import remarkParse from "remark-parse"; import remarkStringify from "remark-stringify";
M joinComponents.jsjoinComponents.js

@@ -1,11 +1,11 @@

-import { writeComponent } from "./writeComponent"; -import { unified } from "unified"; +import rehypeDocument from "rehype-document"; +import rehypeFormat from "rehype-format"; import rehypeParse from "rehype-parse"; import rehypeStringify from "rehype-stringify"; -import rehypeDocument from "rehype-document"; +import { extractFrontmatter } from "./extractFrontmatter"; +import { unified } from "unified"; +import { writeComponent } from "./writeComponent"; import { writePageMain } from "./writePageMain"; -import rehypeFormat from "rehype-format"; -import { extractFrontmatter } from "./extractFrontmatter"; //NOTE right now we're strinfigying, connecting the strings, then parsing for //more rehype processing. I'm sure there's a more correct way to do this, but

@@ -13,27 +13,21 @@ //that can happen later

export async function joinComponents(filepath) { const frontmatter = await extractFrontmatter(filepath); - const recipe = Object.keys(frontmatter).filter((x) => - ["before", "header", "footer", "after"].includes(x), - ); + let recipe = ["before", "header", "main", "footer", "after"]; + for (let i of [0, 1, 3, 4]) { + if (!Object.keys(frontmatter).includes(recipe[i])) { + recipe[i] = null; + } + } + console.log(recipe); let union = ""; - //HACK - if (recipe.includes("header")) { - union += await writeComponent(frontmatter.header, frontmatter, "header"); - } - if (recipe.includes("before")) { - union += await writeComponent(frontmatter.before, frontmatter); - } - union += await writePageMain(filepath); - - if (recipe.includes("after")) { - union += await writeComponent(frontmatter.after, frontmatter); + for (let i of recipe.filter((x) => !!x)) { + union += + i === "main" + ? await writePageMain(filepath) + : await writeComponent(frontmatter[i], frontmatter); } - if (recipe.includes("footer")) { - union += await writeComponent(frontmatter.footer, frontmatter, "footer"); - } - //HACK const processor = unified() .use(rehypeParse, { fragment: true })

@@ -48,3 +42,4 @@

const output = await processor.process(union); return output.value; } +console.log(await joinComponents("./input/content/cookie.md"));