Markdown-Driven Content with Astro Collections
- Date —
- June 15, 2026
- Tags —
- Astro, TypeScript, Markdown
Astro’s content collections let you define a Zod schema for your Markdown frontmatter and get full type safety without any runtime overhead. Every .md file is validated at build time, and the frontmatter fields are typed when you access them in your components.
For this site, I defined two collections — work and blog — each with their own schema. The work collection has fields like role, url, and repo that don’t make sense for blog posts. The blog collection is simpler: title, summary, date, tags, and draft.
How it works
- Define your schema in
src/content.config.tsusingdefineCollection - Drop
.mdfiles into the correspondingsrc/content/<collection>/directory - Use
getCollection()in your pages to fetch and query entries - Use
getStaticPaths()to generate a page per entry
The draft field is a simple boolean that filters entries out of production builds. Setting draft: true in a Markdown file removes it from the collection query entirely.
The best part is that adding a new blog post or project just requires dropping a file in the right directory — no code changes, no component authoring, no route configuration.
ssh controlplanepackage main
func main() { fmt.Println("Hello, World!")}