Setting Up Your First Collection
This is a member-only chapter. Log in with your Signal Over Noise membership email to continue.
Log in to readModule 4 · Section 3 of 9
Setting Up Your First Collection
Create the directory structure:
src/
└── content/
├── config.ts
└── blog/
└── first-post.md
The config.ts file defines your collection schema using Zod (Astro bundles it):
// 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.date(),
tags: z.array(z.string()).default([]),
draft: z.boolean().default(false),
}),
});
export const collections = { blog };
This schema enforces that every post has a title, description, and publication date. If frontmatter is missing or wrong, the build fails with a clear error rather than silently serving broken content.