FREEFirst project with us? Your landing page design is on the house.See the offer

Astro + Sanity

Astro content collections for marketing teams

What Astro content collections are, where your content can live, how schemas stop broken pages, and how to set up collections a marketing team can trust.

By Abdul QuadirUpdated 2026-11-156 min read
TL;DR
  • A content collection is a named set of entries, such as blog posts or case studies, with one schema that every entry must follow.
  • Collections are defined in src/content.config.ts. A loader says where the content comes from, a schema says which fields it must have.
  • Content can live in Markdown or JSON files in your repo, in one data file, or in a CMS through a loader.
  • When an entry breaks the schema, Astro shows an error naming the entry and the field.
  • Schemas give you typed fields, so mistakes show up while building, not on a live page.

The short answer

Astro content collections are named groups of content, such as blog posts, case studies or team members, where every entry follows one schema. You define them in src/content.config.ts. Each collection has a loader, which says where the content comes from, and a schema, which says which fields each entry must have and what type they are.

For a marketing team, that means a post cannot go out without a title, a description that is too long gets flagged, and a category has to be one you agreed on. When an entry breaks the schema, Astro shows an error that names the entry and the field.

Where your content can live

The loader decides where content is stored. Astro's docs describe these options:

OptionWhere content livesGood for
glob() loaderMany files in your repo: Markdown, MDX, JSON, YAML or TOMLBlog posts, case studies, docs
file() loaderOne file with many entries, each with a unique idTeam members, FAQs, logos
Custom or community loaderA CMS or an API, pulled in at build timeContent your team edits in a CMS
Live collectionFetched on each request, defined in src/live.config.tsContent that must be fresh to the minute

Live collections need a server adapter for on-demand rendering, and Astro's docs note they do not support MDX or image optimisation. For most marketing sites, build-time collections are the right default.

What a schema does for marketers

Schemas are written with Zod, imported from astro/zod. Astro's docs call a schema optional but highly recommended. In plain words, a schema lets you say:

  • This field is required. No post without a title, description or date.
  • This text has a length. A meta description between 70 and 160 characters, a title under a set limit.
  • This is one of a list. Category must be one of your agreed categories, so you do not end up with "SEO", "Seo" and "seo".
  • This is an image. The image() helper in the schema validates and imports an image, so it can go straight into Astro's image component.
  • This points to another entry. reference() links a post to an author in another collection.

Astro also generates TypeScript types from the schema, and JSON Schema files in .astro/collections/ that code editors can use to check data files as you type.

Worked example: a case study collection

Here is how we would set up a case study collection for a marketing site. Each field has a reason:

FieldRuleWhy
titleRequired textEvery page needs a heading
descriptionRequired, 70 to 160 charactersBecomes the meta description
clientRequired textUsed on cards and in schema markup
industryOne of a fixed listDrives filters on the work page
cover and coverAltimage() plus required alt textNo image without alt text
servicesList of references to a services collectionLinks case studies to service pages
draftTrue or false, default trueKeeps unfinished work off the site
publishedAtDateSorting and "latest work" lists

With this in place, a new case study either has everything it needs, or the build tells you what is missing.

What a broken entry looks like

Say a writer adds a new post file and forgets the title. Astro does not quietly build a page with an empty heading. It shows an error that names the collection and the entry, for example that the post's data does not match the collection schema, followed by the reason, such as "title" is required.

That message is the point of the whole setup. The person who made the mistake sees exactly which file and which field to fix, before the page reaches a visitor. With no schema, the same mistake ships, and someone finds it weeks later on a phone.

Getting content onto pages

Pages read collections with getCollection() for a list and getEntry() for one item, both from astro:content. Markdown and MDX entries are turned into a component with render().

Two details catch teams out:

  • Filter drafts yourself. getCollection() takes an optional filter, so a list page can leave out entries where draft is true.
  • Sort on purpose. Astro's docs say the order getCollection() returns is not fixed. Always sort by date or a set order field, or your "latest posts" block may shuffle between builds.

Collections in Git or a CMS?

Both work with collections. The question is who edits and how often.

  • Files in Git suit teams who are happy to edit Markdown or JSON, or who ask a developer or an AI tool to make changes. Every change has a history and goes through review.
  • A CMS through a loader suits teams with several non-technical editors, who want a form, image uploads and previews. Sanity is a common pick with Astro; see Astro and Sanity for marketing teams.

A simple rule: if more than one or two people outside the web team publish each week, use a CMS. If not, files in Git are simpler and cost nothing extra. Our headless CMS comparison goes deeper.

Rules we follow for marketing collections

  1. One collection per page type: posts, case studies, authors, FAQs.
  2. Every collection that makes pages has required SEO fields with length rules.
  3. Categories and tags are fixed lists, not free text.
  4. Every image field has a required alt text field next to it.
  5. Every page type has a draft flag, and list pages filter on it.
  6. Every list is sorted on an explicit field.
  7. Shared facts, like prices or team names, live in their own collection and are referenced, never copied.

Common mistakes

  • No schema at all. It works until one entry is missing a field and a page renders empty.
  • Everything optional. A schema where every field is optional catches nothing.
  • Free text categories. Filters break quietly when spelling drifts.
  • Copied facts. A price typed into ten posts goes out of date in nine of them.
  • Choosing live collections by default. They add a server and lose image optimisation. Most marketing content does not need them.

What to do next

List your page types, then write down the fields each one needs and which are required. That list is most of the schema. If you are moving to Astro, our Webflow to Astro and Astro and Sanity pages explain how we set this up, or tell us about your content and we will suggest a structure.

Abdul Quadir
Abdul QuadirFounder of Kookies. Builds Webflow and Astro sites for startups and growing teams.

Terms used: Astro, Content collections

FAQs

Questions
people ask.

Abdul Quadir
Still have a question?Ask us directly. We reply within a day.
Book a callPick a timehello@kookies.io

Named groups of content, such as blog posts or case studies, where every entry follows one schema. They are defined in src/content.config.ts.

In Markdown, MDX, JSON, YAML or TOML files in your repo, in one data file, or in a CMS or API through a custom or community loader.

Astro calls it optional but highly recommended. A schema makes fields required, checks their types and gives you typed data in your pages.

Astro shows an error naming the collection, the entry and the field that does not match, such as a missing title.

Yes. A custom or community loader can pull entries from a CMS or API, and the same schema checks them.

Collections fetched on each request instead of at build time. They need a server adapter and do not support MDX or image optimisation.

Your turn

Let's kook
what you krave.

Hi Kookies, I need a built on . I'd love to launch . Reach me at
or book a callSent. We reply within one working day.