astro-content-collections
Skill2 starsChanged 2 months agoMITView on GitHub
Working with Astro content collections, covering schemas with Zod, the glob loader, image() fields, querying, drafts, and rendering. Use when adding or editing content entries, changing a collection schema, or building pages from collection data.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- zerocms-io/astro-content-collectionstheir own version, first seen Nov 1, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- zerocms-io/astro-content-collections★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository2 other files it gives its agents.
- astro-seoSkill
- astro-tailwind-best-practicesSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 44
Import Zod from astro/zod, per the docs.
- Distinctive: line 71
Never invent frontmatter fields: unknown fields are either rejected by a strict schema or silently dropped, and both are bugs.
- Distinctive: line 73
Keep frontmatter values consistent with the collection's existing style (date formats, tag casing, image paths) rather than introducing …
- Very specific: line 86
Every getCollection() call site must apply the filter, including RSS feeds and sitemaps, which are the classic leak (field convention).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Astro content collections
How to define, edit, and query content collections without breaking the build. Each rule either follows the official content collections docs (linked) or is a field convention from maintaining large content sites, marked as such.
Where collections live
- Collections are defined in
src/content.config.tsat the project root ofsrc/(older projects:src/content/config.ts). OnedefineCollection()per collection, exported in a singlecollectionsobject. The standard local setup uses the
glob()loader with abasedirectory and filepattern:import { defineCollection } from "astro:content"; import { glob } from "astro/loaders"; import { z } from "astro/zod"; const posts = defineCollection({ loader: glob({ base: "./src/content/posts", pattern: "**/*.{md,mdx}" }), schema: z.object({ title: z.string(), description: z.string(), pubDate: z.coerce.date(), }), }); export const collections = { posts };- Entry
ids are generated from filenames (URL-friendly, lowercased). An entry can override its ownidwith aslugfrontmatter property.
Schema rules
- Import Zod from
astro/zod, per the docs. - Dates in frontmatter arrive as strings or dates depending on quoting, so
use
z.coerce.date()to handle both. Image fields use the
image()helper, notz.string():schema: ({ image }) => z.object({ cover: image(), }),The field then resolves to an
ImageMetadataobject with real dimensions. Pass it straight to<Image />fromastro:assets; never treat it as a string path. (Note:image().refine()custom checks are unsupported.)- Link entries across collections with
reference("collection-name")instead of storing raw ids in strings. - Changing a schema is a three-part task (field convention): update the schema, update every existing entry that no longer validates, and update any AGENTS.md or docs describing the frontmatter. A schema change that only touches the config file is almost certainly incomplete.
Editing and adding entries
Field conventions:
- New entries start as a copy of an existing entry's frontmatter, then edit. Never invent frontmatter fields: unknown fields are either rejected by a strict schema or silently dropped, and both are bugs.
- Keep frontmatter values consistent with the collection's existing style (date formats, tag casing, image paths) rather than introducing variants.
Drafts
Two working patterns; check which one the project already uses:
A
draftboolean in the schema, filtered at query time, per the docs:const published = await getCollection("posts", ({ data }) => !data.draft);Every
getCollection()call site must apply the filter, including RSS feeds and sitemaps, which are the classic leak (field convention).Underscore-prefixed filenames excluded by the loader pattern (field convention: one exclusion point, no filters to forget):
loader: glob({ base: "./src/content/posts", pattern: ["**/*.md", "!**/_*"] }),
Querying and rendering
getCollection()returns entries in non-deterministic order, per the docs. Anything user-facing sorts explicitly:const posts = (await getCollection("posts")).sort( (a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf(), );Render Markdown/MDX bodies with
render()fromastro:content:--- import { getEntry, render } from "astro:content"; const entry = await getEntry("posts", Astro.params.slug); if (!entry) return Astro.redirect("/404"); const { Content, headings } = await render(entry); --- <Content />- Build routes from entries with
getStaticPaths()mapping overgetCollection(), usingpost.idfor the URL param.
Before finishing
- No invented frontmatter fields; new entries validate against the schema
- Image fields use
image()and are passed as metadata, not strings - Every user-facing
getCollection()call sorts explicitly - Draft filtering applied everywhere entries are listed (pages, RSS, sitemap)
- Schema changes shipped together with entry and docs updates
astro buildpasses (schema errors surface at build time)
Maintained by Michael Andreuzza at Lexington Themes: Astro + Tailwind themes that ship with AGENTS.md, scoped rules, and design skills out of the box.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

