Free auditStart free
GuideSanity · Crawling

Sanity XML sitemap

Query page documents with GROQ, build absolute URLs and real lastmod dates in your frontend, and fix the defaults in Sanity's own sitemap lesson.

3 min
read
5
sources
Oct 29, 2026
updated
Scaplet Editorial Team
author
In one line

Sanity does not output a sitemap; your frontend builds one from documents. Write a GROQ query that returns each public document's path and _updatedAt, map it to absolute canonical URLs in a sitemap route, and return the XML. Sanity's own lesson works as a base but sets priority and changeFrequency, which Google ignores, and builds the origin from a deployment URL.

30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
02Worth knowing

Keep drafts and non-public documents out

Sanity's perspectives documentation says the published perspective excludes all unpublished changes from results, while raw returns drafts, versions and published content side by side for authenticated requests. Set perspective: 'published' on the client that powers the sitemap so a draft-only page cannot slip in.

Add an indexing field

If an editor can mark a page noindex, filter it in the query (for example && noindex != true) so the sitemap never lists a URL that tells Google to skip it.

Mirror your routes

If a document redirects elsewhere, its old path should not appear. Pair the sitemap query with your Sanity redirects list.

Split at the limit

Google caps one sitemap at 50MB (uncompressed) or 50,000 URLs; Sanity's lesson repeats the 50,000 URL cap. Beyond that, create several sitemaps and a sitemap index.

Client for the sitemap route (example)
import { createClient } from '@sanity/client'

export const sitemapClient = createClient({
  projectId: '<your-project-id>',
  dataset: '<your-dataset>',
  apiVersion: '2023-05-03',
  useCdn: false,
  perspective: 'published',
})
03How it works

Check it worked

  1. 1

    Open the file

    Visit /sitemap.xml on the deployed site. Every <loc> should start with your production origin, not localhost or a .vercel.app host.

  2. 2

    Compare counts

    Run count(*[...]) as a GROQ query with the same filter as the sitemap query and compare the result with the number of <url> entries.

  3. 3

    Publish a change

    Publish a page in Studio and confirm its URL appears after your site's next rebuild or revalidation. Unpublish another and confirm it disappears.

  4. 4

    Submit it

    Add the sitemap URL under Sitemaps in Search Console and read the status. Sanity's glossary also advises referencing the file in robots.txt.

Sources · 5

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • sanity.io
  • google.com
  • vercel.com
  1. 01Build a dynamic sitemap | Sanity Learnsanity.io · checked 2026-11-01
  2. 02Sitemap.xml definition | Sanity Glossarysanity.io · checked 2026-11-01
  3. 03Perspectives | Sanity Docssanity.io · checked 2026-11-01
  4. 04Build and submit a sitemap | Google Search Centraldevelopers.google.com · checked 2026-11-01
  5. 05System environment variables | Vercel Docsvercel.com · checked 2026-11-01
Questions

Asked a lot.

2 questions people ask next, answered from the sources on this page.

01Does Sanity generate sitemap.xml automatically?

No. Sanity stores documents and answers GROQ queries. Your frontend turns that query result into a sitemap route or generated file.

02Should I include priority and changefreq?

No. Google says it ignores both values, so they add nothing for Google and only create things to maintain.

Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane