Files
medusa-store/www/packages/docs-utils/src/get-front-matter.ts
Shahed Nasser 16ae192456 docs: add tags package to generate tags (#10666)
* initial changes

* finalize implementation

* run generator on prep

* remove tags package from book

* optimization attempt

* test transpile

* test transpile

* rename utils

* rename directory

* add vercel ignore

* add tags to book
2024-12-19 13:15:42 +02:00

31 lines
826 B
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
}