all repos — kushiyaki @ 8e7c9d2ed42b7aad6b479eb4bb7026f7348b9003

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

feat: refactor to use vfile
trickyni trickyniv56@gmail.com
Sat, 09 May 2026 17:35:21 +0300
commit

8e7c9d2ed42b7aad6b479eb4bb7026f7348b9003

parent

105a5c68574814d737ceb68a86d1dc45cfca7728

1 files changed, 13 insertions(+), 27 deletions(-)

jump to
M createSiteIndex.jscreateSiteIndex.js

@@ -1,31 +1,17 @@

import { glob } from "glob"; -import { readFile } from "fs-extra"; -import { unified } from "unified"; -import remarkParse from "remark-parse"; -import remarkFrontmatter from "remark-frontmatter"; -const yaml = require("js-yaml"); - -export async function extractFrontmatter(filepath) { - let frontmatter; - - const processor = unified() - .use(remarkParse) - .use(remarkFrontmatter, "yaml") - .use(() => (tree) => { - frontmatter = yaml.load(tree.children[0].value, { - schema: yaml.FAILSAFE_SCHEMA, - }); - frontmatter.filename = filepath.split("/").pop().split(".").shift(); - }); - processor.run(processor.parse(await readFile(filepath, "utf-8"))); - - return frontmatter; -} +import { read } from "to-vfile"; +import { matter } from "vfile-matter"; export async function createSiteIndex() { - let siteIndex = []; - for (const file of await glob("input/**/*.md", { nodir: true })) { - siteIndex.push(await extractFrontmatter(file)); - } - return siteIndex; + let site = await glob("input/**/*.md", { nodir: true }); + return Promise.all( + site.map(async (page) => { + let file = await read(page, "utf-8"); + matter(file); + file.data.matter.filename = file.stem; + return file.data.matter; + }), + ); } + +// console.log(await createSiteIndex());