Dynamic Sitemap Updating in Production #70787
-
SummaryHello, I was wondering if it's possible to update the Say we have blog posts or news articles, for example, and as more posts are published, the "list of valid URLs" (or something similar) would update. How would I then update the sitemap? Is it possible? My idea is to add two endpoints (with proper authentication) that, when called, regenerate said files for my application. Initial testing with this kind of approach did not work. My endpoints called the real functions to generate Currently I'm just rebuilding the complete application again every 24h through a GH Actions Cron job. The cron job could instead of rebuild just call the endpoints. Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
According to the docs, https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap:
So you should be able to export one of these, https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config, such as revalidate, to have it regenerate at runtime. Alternatively, as the docs say, a sitemap file is a special Route Handler, so you could just make a Router Handler, that returns XML, and revalidates every now and then. #52831 - though that shouldn't be necessary.
|
Beta Was this translation helpful? Give feedback.
According to the docs, https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap:
So you should be able to export one of these, https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config, such as revalidate, to have it regenerate at runtime.
Alternatively, as the docs say, a sitemap file is a special Route Handler, so you could just make a Router Handler, that returns XML, and revalidates every now and then. #52831 - though that shouldn't be necessary.
I'll run a couple of local tests with revalidate to see it if works, but i…