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.xmlfor root sitemap response./(sitemap)/sitemaps/[sitemapLanguageCode]/sitemap.xmlfor per-language sitemap responses on multilingual sites./(sitemap)/sitemap-style.xslis referenced by sitemap output viaSITEMAP_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.currentorslug.current. - Adds translated alternates from
translation.metadatawhere 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_ALLandCACHE_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.
Last updated: 27 Apr 2026, 14:59:48
