swbanga.com

Technical article

By Super Washington Banga6 min readEngineering

Why your content pipeline should validate at build time

Frontmatter validation at build time catches authoring errors before they reach production — here is the pattern and its guarantees.

The failure mode

A content site without validation has two failure modes: silently dropped fields (Zod's default is to strip unknown keys) and typo'd field names that render empty sections. Both ship to production unnoticed.

The fix

Every .mdx file under the repository's content directory is parsed with gray-matter and validated with a strict Zod schema during static generation:

ts
const parsed = schema.safeParse(file.data);
if (!parsed.success) {
  throw new Error(
    `Invalid frontmatter in ${filePath}:\n${formatZodIssues(parsed.error)}`,
  );
}

What you get

  • A build that fails loudly with the file path and the offending field
  • A single canonical field contract for every content type
  • No runtime cost: the validator executes once, at build time

Comments are currently disabled. Coming soon!