fumadocs-core
Version:
The React.js library for building a documentation website
24 lines (23 loc) • 545 B
JavaScript
import { parse } from "yaml";
// src/content/md/frontmatter.ts
/**
* Inspired by https://github.com/jonschlinkert/gray-matter
*/
const regex = /^---\r?\n(.+?)\r?\n---\r?\n?/s;
/**
* parse frontmatter, it supports only yaml format
*/
function frontmatter(input) {
const output = {
matter: "",
data: {},
content: input
};
const match = regex.exec(input);
if (!match) return output;
output.matter = match[0];
output.content = input.slice(match[0].length);
output.data = parse(match[1]) ?? {};
return output;
}
export { frontmatter };