Skip to main content
Search and Discovery

Sitemap

XML sitemap generation with site/language scoping, visibility filtering, translation alternates, and cache tagging.

The starter provides route-based XML sitemap generation with support for both single-locale and multilingual sites. Sitemap entries are built from Sanity documents and filtered by document visibility settings.

Route structure

Implemented routes:

  • /(sitemap)/sitemap.xml for root sitemap response.
  • /(sitemap)/sitemaps/[sitemapLanguageCode]/sitemap.xml for per-language sitemap responses on multilingual sites.
  • /(sitemap)/sitemap-style.xsl is referenced by sitemap output via SITEMAP_XSL_URL.

For multilingual sites, root sitemap.xml returns an index pointing at language-specific sitemap URLs.

Inclusion logic

Entries are generated by sanityDocumentsToSitemapEntries():

  • Queries only DOCUMENTS_IN_SITEMAP.
  • Filters by site and optional language.
  • Excludes documents where visibilityOptions.includeInSitemap == false.
  • Resolves pathname from pathname.current or slug.current.
  • Adds translated alternates from translation.metadata where valid for the current site.

Caching and invalidation

Sitemap routes use unstable_cache with:

  • Revalidation set by seo.sitemapCacheSeconds (12 hours by default).
  • Tags including CACHE_TAG.SANITY_ALL and CACHE_TAG.SITEMAP.

Sanity query calls are also tagged with document-level cache tags, enabling targeted invalidation strategies when content changes.

Operational behaviour

  • Requests validate site and language before generating output.
  • Invalid site/language combinations return notFound().
  • Response content type is application/xml.

This keeps sitemap output valid, scoped, and resilient in multi-site deployments.

Edit this page on GitHub

Last updated: 27 Apr 2026, 14:59:48

Was this helpful?

On this page