Guide
Content Collection
A group of related content entries in a static site generator, typically with a shared schema and organized in a specific directory.
Publié
Sommaire
Définition
A group of related content entries in a static site generator, typically with a shared schema and organized in a specific directory.
Content collections are typed, validated groups of content entries that enable structured authoring and programmatic access to content in static site generators.
Features
- Schema Validation: Type-safe frontmatter
- Query API: Programmatic access to content
- Relationships: Link between entries
- TypeScript Support: Full type safety
Astro Implementation
const guides = defineCollection({
loader: glob({ pattern: "**/*.mdx", base: "./src/content/guides" }),
schema: z.object({
title: z.string(),
publishedAt: z.coerce.date(),
}),
});
Benefits
- Build-time validation
- Type-safe content access
- Consistent structure
- Better developer experience
- Easier refactoring