feat: support component arrays
trickyni trickyniv56@gmail.com
Sat, 09 May 2026 17:36:08 +0300
2 files changed,
23 insertions(+),
3 deletions(-)
M
.gitignore
→
.gitignore
@@ -8,3 +8,4 @@ input_1
deprecated input.bak __design-document.md +deprecated
M
insertJSX.js
→
insertJSX.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" + } + } }; }