Astro: Content Collection
September 11, 2025 · minute read
In Astro, we can manage sets of content using Content collections. Create a src/content/config.ts in your project and define collections using defineCollection with schema using Zod for type safety.
import { defineCollection, z } from "astro:content";import { glob } from "astro/loaders";
const posts = defineCollection({ loader: glob({ pattern: "**/*.{md,mdx}", base: "./src/content/posts" }), schema: ({ image }) => z.object({ draft: z.boolean(), title: z.string(), description: z.string(), pubDate: z.coerce.date(), cover: image().optional(), tags: z.array(z.string()).optional(), }),});
export const collections = { posts };Always glad to have you here, check back now and then for updates. 😄