Montacasa's frontend sitemap generator


0.0.183 years ago3 years agoMinified + gzip package size for @montacasa/sitemap-generator in KB


Sitemap Generator

Generates a sitemap.xml from a given list of links.

It can also generate multiple sitemaps and a sitemap index file, if the number of links exceeds the maximum per sitemap.


  • Install the package with npm i @montacasa/sitemap-generator.
  • And run it with a list of links - either a variable of type array or a file containing one link per line.

Example with a variable

  const generator = require('@montacasa/sitemap-generator');

  // Define the sitemap urls
  const urls = [

  // ..and some other options
  const filepath = './src/sitemap.xml';
  const domain = 'https://www.example.com';

  // Create an async function
  const sitemap = async() => {
    const message = await generator({domain, filepath, urls});

  // Generate!
  sitemap(); // 'DONE! One single sitemap generated with 3 links.'



An array of links. Optional.


    // ...


A file path for a list of links. Optional.

E.g.: ./urls containing:



The maximum number of links per sitemap. Optional, default is 50.000 according to sitemaps.org FAQ.


The path to which the generator should write the sitemap(s). Optional, default is ./sitemap.xml.


Optional. If not provided, the domain is extracted from the first link in the links list (either the file or array).

The domain is to be used in the sitemap index file. E.g.:

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

List of links

Both urls and file are optional, but you must provide either one or another!

If both urls and file are provided, file will prevail over urls.

Multiple sitemaps

If the number of links in urls or file is higher then max, the sitemap will be split in as many sitemaps as needed at the same dir, and a sitemap index will be created at filepath.

In that case, supposing you are using default values, sitemap.xml would be the sitemap index and the sitemaps would be named sitemap-0.xml, sitemap-1.xml and so on, with maximum 50k links each. (See example above.)

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.