TIL: Astro Content Collections
A quick note on how Astro's content collections with Zod schemas make managing structured data surprisingly pleasant.
I just set up content collections in Astro for this site, and they hit a sweet spot I didn’t know I was looking for.
The setup: structured content (work history, publications, projects) lives in YAML files. Blog posts live in MDX files. Both go through a Zod schema. If a field is missing or the wrong type, the build fails with a clear error. No runtime surprises, no database, no CMS.
For the timeline on my Proof of Work page, each entry is a YAML file with fields like type, title, organization, startDate, summary, description, links, etc. YAML works well here because the shape is predictable. Same fields every time, no prose.
Blog posts are different. They’re mostly writing, but I want the option to drop in a chart or a custom component when it helps. That’s what MDX is for: Markdown plus JSX. Write paragraphs like normal, embed a React component when you need one.
The workflow that makes me happy: to publish a new post, I create a file at src/content/blog/YYYY-MM-DD-slug.mdx, push to main, and the post is live. No CMS, no admin panel, no clicking through a form to add a “blog entry.”
I’m sure people who’ve used Astro for a while shrug at this. But coming from setups where adding a project meant either hand-editing a JSON blob or wiring up a headless CMS, files-with-schemas feels like the right amount of structure.