Public
Script
Readme

Extract yaml front matter from a md string

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import rehypeDocument from "https://esm.sh/rehype-document";
import remarkFrontmatter from "https://esm.sh/remark-frontmatter";
import remarkParse from "https://esm.sh/remark-parse";
import remarkStringify from "https://esm.sh/remark-stringify";
import { unified } from "https://esm.sh/unified";
import { matter } from "npm:vfile-matter";
function yamlMetadataHandler() {
return function(tree, file) {
matter(file);
};
}
export async function extractMetadata(key: string, markdown: string) {
const file = await unified()
.use(remarkParse)
.use(remarkStringify)
.use(remarkFrontmatter)
.process(markdown);
matter(file, { strip: true });
return file.data.matter[key];
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
December 1, 2023