Content Collection Schema
About 148 wordsLess than 1 minute
2026-09-01
The post-field contract lives in src/content.config.ts. Astro Content Collections parse frontmatter during the build and validate types, dates, and allowed values.
Schema and Fields
const posts = defineCollection({
loader: glob({ pattern: "**/*.{md,mdx}", base: "./src/content/posts" }),
schema: () => z.object({
title: z.string(),
published: z.coerce.date(),
draft: z.boolean().default(false),
}),
});The source schema is authoritative; see Frontmatter for the field reference. Unknown fields cannot safely be consumed by components.
Extending Fields
- Add a field with the right default or optionality.
- Update
src/types/and every consumer. - Update Frontmatter documentation and examples.
- Run
npx astro check,pnpm type-check, andpnpm build.
Follow the project's date convention instead of mixing strings and Date values. Production collection queries exclude draft: true; an encrypted: true post must also have a non-empty password.
Copyright
Copyright Ownership:matsuzaka-yuki
License under:Attribution 4.0 International (CC-BY-4.0)