Excluding noindex pages from next-sitemap in a custom implementation

1 replies
Last updated: Jun 22, 2023
Hi all 👋 so we are using the next-sitemap, but I'd like to exclude all pages that are set to noindex. I have been told that "As discussed, this looks relatively tricky to achieve with the current implementation (next-sitemap) due to the fact that it executes after the main site build, and outside the scope where access to Sanity is available." but I'd like to verify this. It seems like a pretty obvious thing most people would want so I'm surprised this is considered a tricky thing to achieve. Any tips?
Jun 21, 2023, 8:19 AM
We made our own that runs in preBuildUtilities.js 🙂It’s a very simple loop through all document types we want included, and we exclude the hidden, can rank them according to their _search_priority_ attribute etc.
In the end it’s just a
fs.writeFileSync('./public/sitemap.xml', sitemap)
to write it to the filesystem.
Jun 22, 2023, 8:26 AM

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?