Type-Safe Content Pipelines with Content Collections
From unstructured Markdown to bulletproof TypeScript objects.
Content management in static sites used to be fragile. Typos in frontmatter keys often went unnoticed until production deployment.
Enter Content Collections
With Content Collections, schemas are defined with Zod:
import { defineCollection, defineConfig } from '@content-collections/core'
import { z } from 'zod'
const posts = defineCollection({
name: 'posts',
directory: './content/posts',
include: '**/*.md',
schema: z.object({
title: z.string().min(3),
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
draft: z.boolean().default(false),
}),
})
export default defineConfig({ content: [posts] })Any invalid post fails during the build phase with actionable error messages and line pointers.