Astro’s Content Collections are good at catching frontmatter drift early. These are the small tips that, after a few weeks of running them, I wish I’d put in place from day one.

The short version

  • Pin categories with z.enum([...]). Not string
  • Use z.coerce.date() for dates — easier to write in frontmatter as a plain string
  • Do not put slug in the schema. Astro infers it from the file path
  • For tags, z.array(z.string()).default([]) — give yourself a default empty array

Constraints

  • Astro 5 series, using astro:content
  • TypeScript strict

Things to avoid

slug in the schema breaks the build

slug is a reserved field — putting it in the schema is a type error. Trust the value Astro derives from the file name.

Apply draft exclusion in both places

draft: true posts need to be filtered out in the listing pages and in getStaticPaths. If you forget one of them, the post is still reachable by typing the URL.

Closing

  • The earlier the schema is locked, the easier the operating life that follows
  • Use enum wherever an enum is honest
  • For more on this site’s stack decisions, see Build