TIL: MDX Frontmatter Parsing with Array Support

Jan 10, 2025

Today I learned about the complexities of parsing YAML frontmatter, especially when dealing with array values.

The Challenge

YAML arrays can be written in two formats:

# Inline format
technologies: ["Next.js", "React", "TypeScript"]

# Multi-line format
technologies:
  - Next.js
  - React
  - TypeScript

The Solution

I needed separate parsers for different content types:

  • Simple parser for blog posts (key-value pairs)
  • Complex parser for projects (handles array formats)

This taught me the importance of choosing the right tool for the job and not over-engineering simple use cases.

Gopal Khadka