You can make donations for the maintenance of the project. Donate
sitemap.xml mapper for Next.js projects.
This module have been created to be used at node server side of NextJs. It is meant to be used in server.js so that when the server is initialized it will only run once. If you place it in any of the request handler of the node server performance may be affected.
Usage for static HTML apps
If you are exporting the next project as a static HTML app, create a next-sitemap-generator script file in the base directory.
pagesDirectory should point to the static files output folder.
After generating the output files, run
node your_nextjs_sitemap_generator.js to generate the sitemap.
If you are using
next@^9.4.0, you may have your site configured with getStaticPaths to pregenerate pages on dynamic routes. To add those to your sitemap, you need to load the BUILD_ID file into your config whilst excluding fallback pages:
const sitemap = ;const fs = ;const BUILD_ID = fs;;
// your_nextjs_sitemap_generator.jsconst sitemap = ;;console;
- alternateUrls: You can add the alternate domains corresponding to the available language. (OPTIONAL)
- baseUrl: The url that it's going to be used at the beginning of each page.
- ignoreIndexFiles: Whether index file should be in URL or just directory ending with the slash (OPTIONAL)
- ignoredPaths: File or directory to not map (like admin routes).(OPTIONAL)
- extraPaths: Array of extra paths to include in the sitemap (even if not present in pagesDirectory) (OPTIONAL)
- ignoredExtensions: Ignore files by extension.(OPTIONAL)
- pagesDirectory: The directory where Nextjs pages live. You can use another directory while they are nextjs pages. It must to be an absolute path.
- targetDirectory: The directory where sitemap.xml going to be written.
- sitemapFilename: The filename for the sitemap. Defaults to
- pagesConfig: Object configuration of priority and changefreq per route.(OPTIONAL)
- sitemapStylesheet: Array of style objects that will be applied to sitemap.(OPTIONAL)
- nextConfigPath(Used for dynamic routes): Calls
exportPathMapif exported from
nextConfigPathjs file. See this to understand how to do it (https://nextjs.org/docs/api-reference/next.config.js/exportPathMap) (OPTIONAL)
For now the ignoredPaths matches whatever cointaning the thing you put, ignoring if there are files or directories. In the next versions this going to be fixed.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!