Next.js Discord

Discord Forum

Static (generated at buildtime) sitemap.xml using getStaticPaths?

Unanswered
Alligator mississippiensis posted this in #help-forum
Open in Discord
Avatar
Alligator mississippiensisOP
Hi,

I'm using Next.js for a site that has tons of statically generated content that is fetched from Sanity CMS when the site is built.

I'm using getStaticPaths to create those paths. Is there some way how I can reuse the getStaticPaths in the sitemap generation script? It would make the sitemap generation much easier and less error prone because I could reuse the same logic etc.

Basically I'm looking for a way how to import the component inside of this file:
https://github.com/vercel/next.js/blob/canary/examples/with-sitemap/scripts/generate-sitemap.js


Thank you 🙂

1 Reply

Avatar
Alligator mississippiensisOP
I came up with a nasty hack, inside of getStaticPaths function I also create a public/sitemap-blog-posts.xml file, how ugly is this? Is there some nicer way how to do this?