JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4464
  • Score
    100M100P100Q128486F
  • License MIT

Generate sitemap.xml from nextjs pages

Package Exports

  • nextjs-sitemap-generator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nextjs-sitemap-generator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npmv1 All Contributors

Simple sitemap.xml mapper for NextJs proyects.

Usage

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. The option 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.

OPTIONS

const sitemap = require('nextjs-sitemap-generator');  

sitemap({  
  alternateUrls: {  
      en: 'https://example.en',  
      es: 'https://example.es',  
      ja: 'https://example.jp',  
      fr: 'https://example.fr',  
  },  
  baseUrl: 'https://example.com',  
  ignoredPaths: ['admin'],  
  pagesDirectory: __dirname + "\\pages",  
  targetDirectory : 'static/'  
});

OPTIONS description

  • 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)
  • 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.

Considerations

For now the ignoredPaths matches whatrever cointaning the thing you put, ignoring if ther are files or directories. In the next versions this going to be fixed.

Contributors

Thanks goes to these wonderful people (emoji key):

Daniele Simeone
Daniele Simeone

💻
illiteratewriter
illiteratewriter

📖
goran
goran

💻

This project follows the all-contributors specification. Contributions of any kind welcome!