Parses and serializes YAML frontmatter in markdown, sanitizing values.
// Source: https://github.com/first-fluke/oh-my-agent | License: MIT | Copyright 2026 Eunkwang Shin, Gahyun Kim
// Provided via justclaw.it.com; keep this notice with the code.
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
import { isRecord } from "./type-guards.js";
export interface ParsedFrontmatter {
frontmatter: Record<string, unknown>;
body: string;
}
function sanitizeFrontmatterValue(value: unknown): unknown {
if (value === undefined || value === null) return undefined;
if (Array.isArray(value)) {
return value
.map((item) => sanitizeFrontmatterValue(item))
.filter((item) => item !== undefined);
}
if (isRecord(value)) {
return Object.fromEntries(
Object.entries(value)
.map(([key, item]) => [key, sanitizeFrontma
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key