Files
medusa-store/www/packages/docs-utils/src/get-front-matter.ts
Shahed Nasser e36c054780 docs: improve references loading (#13761)
* docs: improve references loading

* remove comment

* try remove generate metadata

* improvements and fixes
2025-10-16 14:25:01 +03:00

48 lines
1.2 KiB
TypeScript

import remarkFrontmatter from "remark-frontmatter"
import remarkParse from "remark-parse"
import remarkStringify from "remark-stringify"
import { unified } from "unified"
import { read, readSync } from "to-vfile"
import { matter } from "vfile-matter"
import { FrontMatter } from "types"
export async function getFrontMatter(filePath: string): Promise<FrontMatter> {
return (
await unified()
.use(remarkParse)
.use(remarkStringify)
.use(remarkFrontmatter, ["yaml"])
.use(() => {
return (tree, file) => {
matter(file)
}
})
.process(await read(filePath))
).data.matter as FrontMatter
}
export function getFrontMatterSync(filePath: string): FrontMatter {
const content = readSync(filePath)
matter(content)
return content.data.matter as FrontMatter
}
export async function getFrontMatterFromString(
fileContent: string
): Promise<FrontMatter> {
return (
await unified()
.use(remarkParse)
.use(remarkStringify)
.use(remarkFrontmatter, ["yaml"])
.use(() => {
return (tree, file) => {
matter(file)
}
})
.process(fileContent)
).data.matter as FrontMatter
}