What are Content Collections?
Content collections are Astro’s built-in solution for organizing and querying content. They provide:- Type Safety - Automatic TypeScript types generated from your schema
- Validation - Frontmatter is validated against a Zod schema at build time
- Query API - Simple, powerful API to fetch and filter content
- Performance - Content is optimized and cached during build
Content collections are defined in
src/content/config.ts and content files are stored in src/content/<collection-name>/.Blog Collection Schema
The blog collection is defined insrc/content/config.ts with the following schema:
Required Fields
Every blog post must include these fields:- title - The post title (string)
- createdAt - ISO 8601 datetime string (e.g.,
"2025-08-12T04:17:35.590Z") - image - URL to the cover image (string)
- description - Brief post description for SEO and previews (string)
- author - Author’s name (string)
- publish - Whether the post is published (boolean)
- authorImage - URL to author’s avatar image (string)
Optional Fields
- updatedAt - ISO 8601 datetime string for last update
- tags - Array of tag strings (e.g.,
["Guide", "Tutorial"])
Type Safety Benefits
Once defined, the schema provides automatic TypeScript types:Querying Collections
Get All Posts
Filter Published Posts
Sort by Date
Get Recent Posts
This exact pattern is used in
src/pages/blog/[slug].astro:125-132 to display recent articles in the sidebar.Rendering Content
To render a blog post’s content:Collection Structure
File Naming
- Files can use
.mdor.mdxextensions - The filename (without extension) becomes the slug
- Hyphens in filenames create URL-friendly slugs
- File:
guide-to-geometry-dash.md - URL:
/blog/guide-to-geometry-dash - Slug:
guide-to-geometry-dash
Validation Errors
If a post’s frontmatter doesn’t match the schema, you’ll get a build error:Next Steps
- Creating Blog Posts - Learn how to write and publish posts
- Blog System Overview - Understand the full blog architecture
