all repos — kushiyaki @ 1dffdbb23a3ff9aaeef10771ff64a06b3b937df3

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

feat: support component arrays
trickyni trickyniv56@gmail.com
Sat, 09 May 2026 17:36:08 +0300
commit

1dffdbb23a3ff9aaeef10771ff64a06b3b937df3

parent

8e7c9d2ed42b7aad6b479eb4bb7026f7348b9003

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

jump to
M .gitignore.gitignore

@@ -8,3 +8,4 @@ input_1

deprecated input.bak __design-document.md +deprecated
M insertJSX.jsinsertJSX.js

@@ -1,8 +1,27 @@

import { visit } from "unist-util-visit"; import { select } from "hast-util-select"; -export default function insertJSX(componentName, data = {}) { +/* + * DONE filedata + * DONE before/after + * DONE multiple components + * TODO global data + * HACK deduplicate + * HACK make the data validation more elegant + */ +export default function insertJSX(data = {}) { + const siteIndex = this.data("siteIndex"); return async (tree) => { - const fn = await import(`./input/templates/${componentName}.jsx`); //FIX avoid strict filestruct past "input" - tree.children.unshift(fn.default(data)); + if (data.before != undefined) { + for (let x of [data.before].flat().reverse()) { + const fn = await import(`./input/templates/${x}.jsx`); //FIX avoid strict filestruct past "input" + tree.children.unshift(fn.default(data, siteIndex)); //TODO use select on "body" + } + } + if (data.after != undefined) { + for (let x of [data.after].flat().reverse()) { + const fn = await import(`./input/templates/${x}.jsx`); //FIX avoid strict filestruct past "input" + tree.children.push(fn.default(data, siteIndex)); //TODO use select on "body" + } + } }; }