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
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user