Astro content collections

A Note is an evergreen reference, not a dated Post: it lives in the Garden and is valued for staying current. This one recaps how content collections are defined and queried — the kind of thing future-me looks up rather than reads once.

A collection is declared with a schema, then queried by name:

import { defineCollection, z } from 'astro:content';

const garden = defineCollection({
  schema: z.object({ title: z.string(), updatedDate: z.coerce.date() }),
});

export const collections = { garden };

Query it from a page with getCollection('garden').