Astro Islands & SSR (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Astro Content Collections & Type-Safe Schemas with Zod.
senior LevelCode ExampleSystem DesignAstro
In Simple Words:
Content Collections organize Markdown, MDX, or JSON files inside src/content/. By defining a schema in src/content/config.ts using Zod, Astro validates frontmatter properties at build time, preventing runtime bugs and generating auto-complete TypeScript types for posts.
typescript
// src/content/config.ts
import { defineCollection, z } from 'astro:content';
const blog = defineCollection({
type: 'content',
schema: z.object({
title: z.string(),
description: z.string().max(160),
pubDate: z.date(),
author: z.string().default('Editorial Team'),
tags: z.array(z.string()),
draft: z.boolean().default(false),
}),
});
export const collections = { blog };