import double from "./addons/double.js"; //TODO add systemized plugin support import insertJSX from "./insertJSX.js"; import rehypeDocument from "rehype-document"; import rehypeFormat from "rehype-format"; import rehypePresetMinify from "rehype-preset-minify"; import rehypeRaw from "rehype-raw"; import rehypeStringify from "rehype-stringify"; import rehypeWrap from "rehype-wrap"; import remarkParse from "remark-parse"; import remarkRehype from "remark-rehype"; import { matter } from "vfile-matter"; import { read, write } from "to-vfile"; import { unified } from "unified"; import { createSiteIndex } from "./createSiteIndex.js"; import { emptyDir } from "fs-extra"; import cpy from "cpy"; import { glob } from "glob"; await cpy(["input/**", "!input/**/*{.md,.jsx}"], "out", { flat: true }); //copies all the assets into out/ emptyDir("out", { recursive: true }); // clears the output folder const siteIndex = await createSiteIndex(); export async function kushiyaki(filepath) { const file = await read(filepath, "utf-8"); matter(file, { strip: true }); file.data.matter.filename = file.stem; const processor = unified() .data("siteIndex", siteIndex) .use(remarkParse) .use(double) .use(remarkRehype, { allowDangerousHtml: true }) .use(rehypeRaw) .use(rehypeWrap, { wrapper: "main" }) .use(insertJSX, file.data.matter) .use(rehypeDocument, { css: file.data.matter?.css ?? "style.css", title: file.data.matter?.title ?? "untitled", link: [{ href: "favicon.png", rel: "icon", type: "image/png" }], //FIX make filetype-agnostic }) // .use(rehypePresetMinify) //NOTE mainly using this for easier tree traversal .use(rehypeFormat) .use(rehypeStringify); const output = await processor.process(file); output.extname = ".html"; output.dirname = "out"; return output; } for (const file of await glob("input/**/*.md", { nodir: true })) { await write(await kushiyaki(file)); } // console.log(await writePage("./input/content/cookie.md"));