index.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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
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";
emptyDir("out", { recursive: true }); // clears the output folder
await cpy(["input/**", "!input/**/*{.md,.jsx}"], "out", { flat: true }); //copies all the assets into out/
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"));
|