Contact Us
Webflow Premium Partner Ehab Fayez
Back to Agent Skills
Content & Documentation

Astro Content Collections

Manage type-safe content collections in Astro with schema validation and query APIs.

Claude Code Cursor Copilot Windsurf

Overview

Astro Content Collections provide a type-safe way to manage content within Astro projects. AI coding agents can define collection schemas using Zod, create and validate content entries, and build dynamic pages from collections.

Agents can set up content collections for blogs, documentation, products, and other content types with proper schema validation. They can generate content entries with valid frontmatter, create dynamic routes from collections, and query content using Astro's built-in APIs.

Content Collections support Markdown, MDX, JSON, and YAML formats with automatic type inference. Teams can use AI agents to maintain strict content standards, generate content from templates, and ensure all entries conform to the defined schema.

Who Is This For?

  • Define Zod schemas for content collections
  • Generate content entries with valid frontmatter
  • Create dynamic routes from content collections
  • Migrate existing content to Astro Content Collections

Installation

Setup for Claude Code
npx astro add mdx

Configuration

// src/content/config.ts
import { defineCollection, z } from 'astro:content';

const blog = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    description: z.string(),
    pubDate: z.coerce.date(),
    tags: z.array(z.string()).default([]),
    draft: z.boolean().default(false),
  }),
});

export const collections = { blog };