npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@montacasa/sitemap-generator

v0.0.18

Published

Montacasa's frontend sitemap generator

Downloads

18

Readme

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.

Usage

  • 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 = [
    "https://www.example.com/path/1",
    "https://www.example.com/path/2",
    "https://www.example.com/path/3"
  ];

  // ..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});
    console.info(message);
  }

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

Options

urls

An array of links. Optional.

E.g.:

  [
    "https://www.example.com/path/1",
    "https://www.example.com/path/2",
    "https://www.example.com/path/3",
    // ...
  ]

file

A file path for a list of links. Optional.

E.g.: ./urls containing:

"https://www.example.com/path/1"
"https://www.example.com/path/2"
"https://www.example.com/path/3"
...

max

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

filepath

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

domain

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">
  <sitemap>
    <loc>https://www.example.br/sitemap-0.xml</loc>
  </sitemap>
  <sitemap>
    <loc>https://www.example.br/sitemap-1.xml</loc>
  </sitemap>
  <sitemap>
    <loc>https://www.example.br/sitemap-2.xml</loc>
  </sitemap>
</sitemapindex>

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