Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Generates sitemap.xml and robots.txt for Next.js projects from Strapi webhooks and at build time.
Next.js Strapi Sitemap & Robots.txt Generator is an open-source Node.js script that produces sitemap.xml and robots.txt for Next.js websites, refreshed automatically by Strapi webhooks and at build time. It is a small utility that lives in a scripts folder of a Next.js project and listens for content changes in Strapi CMS to keep search engine files current.
The generator is a Node.js script that reads configuration from a .env file (PORT, HOST, BACKEND_HOST, WEBHOOK_TOKEN) and outputs sitemap files into a subfolder of the public directory plus a robots.txt at the root. It was authored by GitHub user stovv and has 6 stars on the repository stovv/next-strapi-sitemap. The tool is designed specifically for projects that use Next.js with Strapi as a headless CMS, and it runs on a Node server alongside next start.
generate function from next.config.js inside the webpack server build hook, the script generates sitemaps and robots.txt on every next build, so production deployments always start with fresh files.sitemaps under the public folder, while the index sitemap stays at the public root./api/ and /login, and the generator writes those rules into robots.txt.yarn start or npm run start.This generator is for Next.js developers who build sites on Strapi and want sitemaps that stay in sync with content without manual rebuilds. It also suits SEO-focused teams that need to exclude private paths like /api/ and /login from robots.txt and prefer to have sitemaps ready at build time rather than generated at runtime.
You clone the repository into a scripts folder, run yarn install (or npm install), and update the start command to call node sitemap-generator.js after next start. In Strapi admin, you create a webhook with the URL http://localhost:PORT, add an Authorization header with your token, and select create, update, and delete actions. When Strapi sends a webhook request, the generator re-reads content and writes fresh sitemaps; during next build, the webpack hook runs the generate function with your site host, sitemap subfolder, public folder path, and disallowed routes.
Yes, the source code is publicly available in the stovv/next-strapi-sitemap repository and no commercial license or fee is mentioned.
The webhook-triggered updates require a Strapi instance, because the generator listens for Strapi's webhook calls. The build-time generation can run without Strapi if you call the generate function manually in next.config.js.
It uses Yarn or npm for dependencies and runs as a Node script alongside Next.js. The instructions assume a typical Next.js project with a scripts folder and a package.json start script.