feat: merge extractFrontmatter into createSiteIndex
trickyni trickyniv56@gmail.com
Fri, 08 May 2026 23:47:02 +0300
3 files changed,
26 insertions(+),
21 deletions(-)
M
.gitignore
→
.gitignore
@@ -4,3 +4,7 @@ __TODO.md
design-document.md node_modules addons +input_1 +deprecated +input.bak +__design-document.md
M
createSiteIndex.js
→
createSiteIndex.js
@@ -1,5 +1,26 @@
-import { extractFrontmatter } from "./extractFrontmatter"; 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; +} export async function createSiteIndex() { let siteIndex = [];
D
extractFrontmatter.js
@@ -1,20 +0,0 @@
-import { readFile } from "fs-extra"; -import { unified } from "unified"; -import remarkParse from "remark-parse"; -import remarkStringify from "remark-stringify"; -import remarkFrontmatter from "remark-frontmatter"; -const yaml = require("js-yaml"); - -export async function extractFrontmatter(filepath) { - let frontmatterObj; - await unified() - .use(remarkParse) - .use(remarkFrontmatter, "yaml") - .use(() => (tree) => { - frontmatterObj = yaml.load(tree.children[0].value); - frontmatterObj.filename = filepath.split("/").pop().split(".").shift(); - }) - .use(remarkStringify) - .process(await readFile(filepath, "utf-8")); - return frontmatterObj; -}