Content Collections
Content Collections provide type-safe content with schemas.
Install content package (if not already):
npm i -D @astrojs/content
Create src/content/config.(ts|js)
:
import { defineCollection, z } from 'astro:content';
const blog = defineCollection({ schema: z.object({ title: z.string(), date: z.string(), draft: z.boolean().optional(), }),});
export const collections = { blog };
Add entries under src/content/blog/
and query with getCollection()
.