Skip to main content
CMSquestions

How To Generate Sitemaps From CMS Content

IntermediateQuick Answer

TL;DR

Generate XML sitemaps from CMS content by querying your CMS API for all published pages, mapping each to a URL with metadata (lastmod, changefreq, priority), and outputting valid XML. In Next.js, use the `sitemap.ts` file convention or a dynamic API route. Regenerate the sitemap when content changes using webhooks or include it in your build process. Submit the sitemap to Google Search Console for faster indexing.

Key Takeaways

  • Query your CMS API for all published content slugs and generate XML sitemap entries programmatically
  • Include lastmod dates from CMS document timestamps for accurate freshness signals to search engines
  • Regenerate sitemaps when content changes — either at build time or via on-demand revalidation