Astro Islands & SSR (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What are Astro Content Collections (`src/content/`)?
senior LevelCode ExampleSystem DesignAstro
In Simple Words:
Astro provides a structured, type-safe content engine inside src/content/:
typescript
// src/content/config.ts
import { defineCollection, z } from 'astro:content';
const blog = defineCollection({
type: 'content',
schema: z.object({
title: z.string(),
publishDate: z.date(),
author: z.string().default('Anonymous'),
tags: z.array(z.string()),
draft: z.boolean().default(false)
})
});
export const collections = { blog };
- If a markdown file has a missing
publishDateor invalid YAML format, the Astro compiler throws a build error with line numbers! - Queries are fully typed:
const posts = await getCollection('blog');.