support for stripping off frontmatter

This commit is contained in:
2023-04-29 17:19:34 -07:00
parent 8c33dd7a1a
commit a26588835b
6 changed files with 64 additions and 1 deletions

18
src/frontmatter.ts Normal file
View File

@@ -0,0 +1,18 @@
import * as yaml from 'yaml';
export function process_frontmatter(document: string) {
if (! document.startsWith('---\n')) {
return {
frontmatter: null,
markdown: document,
};
}
const endIndex = document.slice(3).indexOf('\n---\n') + 3;
const frontmatterYaml = document.slice(3, endIndex);
const markdown = document.slice(endIndex + 4);
const frontmatter = yaml.parse(frontmatterYaml);
return { frontmatter, markdown };
}