The validated type of the frontmatter (inferred from schema)
Array of parsed markdown files with untyped frontmatter
Zod schema defining the expected frontmatter structure
Object containing statistics, errors, and validated files with typed frontmatter
Validate and use typed frontmatter
const { successful } = await getMarkdownObjects('./posts');
const validation = validateMarkdownObjects(successful, TechnicalNoteFrontmatterSchema);
if (validation.filesValid === validation.filesFound) {
console.log('All files valid!');
// validatedObjects have typed frontmatter
validation.validatedObjects.forEach(obj => {
console.log(obj.markdownObject.frontMatter.title); // Type-safe!
});
} else {
console.log(`${validation.filesValid}/${validation.filesFound} valid`);
console.error(validation.validationErrors.join('\n'));
}
Validates markdown frontmatter against a Zod schema and returns typed results.
Takes untyped parsed markdown files and validates their frontmatter against the provided Zod schema. Successfully validated files are returned with properly typed frontmatter, while validation errors are collected for review.