Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sitemap-stream

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sitemap-stream

Simple and fast sitemap stream that respects google rules

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
increased by250%
Maintainers
1
Weekly downloads
 
Created
Source

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();

Keywords

FAQs

Package last updated on 31 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc