all repos — kushiyaki @ d9ad97c127b24fb66a08134f0fad6233ab7ae482

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

insertJSX.js (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
import { select } from "hast-util-select";
/*
 * DONE filedata
 * DONE before/after
 * DONE multiple components
 * DONE global data
 * HACK deduplicate
 * HACK make the data validation more elegant
 */
export default function insertJSX(data = {}) {
  const siteIndex = this.data("siteIndex"); // calls siteIndex from the processor

  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"
      }
    }
  };
}