Riadh Chelbi
← All posts

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

  1. Define your schema in src/content.config.ts using defineCollection
  2. Drop .md files into the corresponding src/content/<collection>/ directory
  3. Use getCollection() in your pages to fetch and query entries
  4. 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.

Terminal window
ssh controlplane
package main
func main() {
fmt.Println("Hello, World!")
}