fix: more correct writeComponent calls
trickyni trickyniv56@gmail.com
Tue, 05 May 2026 15:08:42 +0300
2 files changed,
19 insertions(+),
23 deletions(-)
M
extractFrontmatter.js
→
extractFrontmatter.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.js
→
joinComponents.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"));