import * as yaml from 'yaml'; export function process_frontmatter(document: string, parse = true) { 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 = parse ? frontmatterYaml : yaml.parse(frontmatterYaml); return { frontmatter, markdown }; }