fix: deduplicate glob call
trickyni trickyniv56@gmail.com
Mon, 25 May 2026 14:31:02 +0300
3 files changed,
13 insertions(+),
20 deletions(-)
M
bun.lock
→
bun.lock
@@ -228,7 +228,6 @@ "rehype-minify-style-attribute": "^4.0.1",
"rehype-minify-whitespace": "^6.0.2", "rehype-normalize-attribute-value-case": "^4.0.1", "rehype-parse": "^9.0.1", - "rehype-preset-minify": "^7.0.1", "rehype-raw": "^7.0.0", "rehype-react": "^8.0.0", "rehype-remove-comments": "^6.1.1",@@ -901,8 +900,6 @@
"rehype-normalize-attribute-value-case": ["rehype-normalize-attribute-value-case@4.0.1", "", { "dependencies": { "@types/hast": "^3.0.0", "hast-util-is-element": "^3.0.0", "unist-util-visit": "^5.0.0" } }, "sha512-sdsfY4DgVWO3K9lJHdIQHg+ErgSGxpFJX0lIOo0tpChQ+iaJHMITHWCGofLor1NjcxLZeeMTfJ5Aif85kLhL3g=="], "rehype-parse": ["rehype-parse@9.0.1", "", { "dependencies": { "@types/hast": "^3.0.0", "hast-util-from-html": "^2.0.0", "unified": "^11.0.0" } }, "sha512-ksCzCD0Fgfh7trPDxr2rSylbwq9iYDkSn8TCDmEJ49ljEUBxDVCzCHv7QNzZOfODanX4+bWQ4WZqLCRWYLfhag=="], - - "rehype-preset-minify": ["rehype-preset-minify@7.0.1", "", { "dependencies": { "rehype-minify-attribute-whitespace": "^4.0.0", "rehype-minify-css-style": "^4.0.0", "rehype-minify-enumerated-attribute": "^5.0.0", "rehype-minify-event-handler": "^4.0.0", "rehype-minify-javascript-script": "^5.0.0", "rehype-minify-javascript-url": "^5.0.0", "rehype-minify-json-script": "^4.0.0", "rehype-minify-language": "^3.0.0", "rehype-minify-media-attribute": "^4.0.0", "rehype-minify-meta-color": "^4.0.0", "rehype-minify-meta-content": "^4.0.0", "rehype-minify-style-attribute": "^4.0.0", "rehype-minify-whitespace": "^6.0.0", "rehype-normalize-attribute-value-case": "^4.0.0", "rehype-remove-comments": "^6.0.0", "rehype-remove-duplicate-attribute-values": "^4.0.0", "rehype-remove-empty-attribute": "^4.0.0", "rehype-remove-external-script-content": "^4.0.0", "rehype-remove-meta-http-equiv": "^4.0.0", "rehype-remove-script-type-javascript": "^4.0.0", "rehype-remove-style-type-css": "^4.0.0", "rehype-sort-attribute-values": "^5.0.0", "rehype-sort-attributes": "^5.0.0", "unified": "^11.0.0" } }, "sha512-yI5Jdfkg8cVar+d5GgqL3HdM1uFOSvnjIOuoJz2U5ZDOSTMrxPrFlh1egNzYNdddwVXakUz9ivKeCuZbATsFDQ=="], "rehype-raw": ["rehype-raw@7.0.0", "", { "dependencies": { "@types/hast": "^3.0.0", "hast-util-raw": "^9.0.0", "vfile": "^6.0.0" } }, "sha512-/aE8hCfKlQeA8LmyeyQvQF3eBiLRGNlfBJEvWH7ivp9sBqs7TNqBL5X3v157rM4IFETqDnIOO+z5M/biZbo9Ww=="],
M
index.js
→
index.js
@@ -1,28 +1,33 @@
#!/usr/bin/env bun +import cpy from "cpy"; 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 { emptyDir } from "fs-extra"; +import { glob } from "glob"; import { matter } from "vfile-matter"; import { read, write } from "to-vfile"; +import { resolve } from "path"; import { unified } from "unified"; -import { emptyDir } from "fs-extra"; -import cpy from "cpy"; -import { glob } from "glob"; -import { resolve } from "path"; // Resolve input/putput directories respecting a project's root folder. const inputDir = resolve(process.cwd(), "input"); const outputDir = resolve(process.cwd(), "out"); +const site = await glob(`${inputDir}/**/*.md`, { nodir: true }); + +// mise en place +emptyDir(`${outputDir}`, { recursive: true }); // clears the output folder +await cpy([`${inputDir}/**`, `!${inputDir}/**/*.md`], `${outputDir}`, { + flat: true, +}); //copies all assets into out/ async function createSiteIndex() { - let site = await glob(`${inputDir}/**/*.md`, { nodir: true }); return Promise.all( site.map(async (page) => { let file = await read(page, "utf-8");@@ -32,21 +37,14 @@ return file.data.matter;
}), ); } -// mise en place -emptyDir(`${outputDir}`, { recursive: true }); // clears the output folder -await cpy([`${inputDir}/**`, `!${inputDir}/**/*.md`], `${outputDir}`, { - flat: true, -}); //copies all assets into out/ -const siteIndex = await createSiteIndex(); -// main function 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) + .data("siteIndex", await createSiteIndex()) .use(remarkParse) .use(double) .use(remarkRehype, { allowDangerousHtml: true })@@ -58,7 +56,6 @@ 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);@@ -69,6 +66,6 @@ return output;
} // Loop through function for each page -for (const file of await glob(`${inputDir}/**/*.md`, { nodir: true })) { +for (const file of site) { await write(await kushiyaki(file)); }
M
package.json
→
package.json
@@ -260,7 +260,6 @@ "rehype-minify-style-attribute": "^4.0.1",
"rehype-minify-whitespace": "^6.0.2", "rehype-normalize-attribute-value-case": "^4.0.1", "rehype-parse": "^9.0.1", - "rehype-preset-minify": "^7.0.1", "rehype-raw": "^7.0.0", "rehype-react": "^8.0.0", "rehype-remove-comments": "^6.1.1",