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

sitemap-stream

v2.0.1

Published

Simple and fast sitemap stream that respects google rules

Downloads

73

Readme

Build Status Coverage Status

sitemap-stream

SitemapStream is a simple and fast tool that build sitemaps using streams.
It automatically creates separated files, following the Google specifications

You can find information about the sitemap's syntax here (you'll find the authorized values the #inject method can receive).

Notes:

  • This package respects the semver and the keep a changelog specifications.
  • This module's code is using ES6 features, so you'll probably need to run your application with the flag --harmony (depending to your Node version).

Install

npm i sitemap-stream

Methods

SitemapStream#Constructor(options):

{
  sitemapDirectoryUrl: String,
  limit: Number, // (default: 50000)
  isMobile: Boolean, // (default: false)
  outputFolder: String // (default: './')
  toCompress: Boolean // (default: true)
}

SitemapStream#inject(url || options)

Url Case:

// The url

Options Case:

{
  url: String, // (required)
  changeFreq: String,
  priority: String
}

SitemapStream#reset

Useful if you want to start writing a new sitemap using the same SitemapStream instance

Events

SitemapStream use streams, so it emit events to let you know what happens. Here are the events you can listen to:

error

sg.on('error', err => {
  console.error(`Something wrong happened: ${err}`);
});

drain

let i = 0;

function injectUrls() {
  while (i<1000000) {
    const isInjected = sg.inject(`http://test-${i}.com`);

    if (!isInjected) return i;

    i++;
  }
}

sg.on('drain', () => {
  console.info(`Because we have injected a big amount of lines in a short time, the stream could need to be drained, in this case, the sg#inject method returns false and the drain event is emitted when the stream is ready to write again`);

  injectUrls();
});

injectUrls();

sitemap-created

sg.on('sitemap-created', path => {
  console.info(`A sitemap file has just been written here: ${path}`);
});

sitemap-index

sg.on('sitemap-index', path => {
  console.info(`A sitemapindex file has just been written here: ${path}`);
});

done

sg.on('done', nbFiles => {
  console.info(`The job is done, we have written ${nbFiles} files !`);
});

Examples

Basic

  const sg = require('sitemap-stream')();

  sg.inject('/some-path');

  sg.inject({ url: '/another-path' });

  sg.inject({ url: '/my-last-path', changeFreq: 'daily', priority: 0.7 });

  sg.done();

With options

  const sg = require('sitemap-stream')({ isMobile: true });

  sg.inject('/some-path');

  sg.inject({ url: '/another-path' });

  sg.inject({ url: '/my-last-path', changeFreq: 'daily', priority: 0.7 });

  sg.done();

With Events

  const sg = require('sitemap-stream')();

  sg.on('sitemap-created', (fileName) => {
    // This listener will be trigger twice, one when the first 50 000 urls will be injected, and another time when you'll call the #done method  
    console.log('A sitemap has been created !');
  });

  sg.on('sitemapindex-index', () => {
    // When  listener will be trigger once the sitemapindex file will be written
    console.log('The sitemapindex has been created, we are done !');
  });

  sg.on('done', () => {
    console.info('Everything is done !');
  });

  for (let i=0; i<60000; i++) sg.inject(`/some-path-${i}`);

  sg.done();