import { visit } from "unist-util-visit"; import { select } from "hast-util-select"; /* * 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) => { 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" } } }; }