Socket
Socket
Sign inDemoInstall

sitemap-creator

Package Overview
Dependencies
81
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sitemap-creator

Crawls a site and creates sitemaps based on glob patterns


Version published
Weekly downloads
6
increased by200%
Maintainers
1
Install size
5.03 MB
Created
Weekly downloads
 

Readme

Source

sitemap-creator

A sitemap generator based on glob patterns. The lastmod tag can also be set to pull from the last modified time of a different file.

Installation

$ npm install --save sitemap-creator

Usage

Basic usage

const sitemap = require('sitemap-creator')

sitemap({
		url: 'http://www.example.com/',
		content: {
			'/': {
				priority: 1,
				lastmod: '2015-06-27T15:30:00.000Z'
			},
			'/page/*': {
				priority: 0.7,
				changefreq: 'monthly'
			}
		},
		outputFile: './sitemap.xml'
	})
	.then(console.log)
	.catch(console.error)


Dynamic timestamps:

A function or a string can be supplied as the lastMod.

sitemap({
		url: 'http://www.example.com/',
		content: {
			'/content/**/*': {
				lastMod: '2017-02-22T21:31:44.000Z'
			},
			'/page/*': {
				fileTimestamp: function(path, cb){
					const json = require('./data.json')
					cb(json.lastModified)
				}
			}
		},
	})
	.then(console.log)
	.catch(console.error)

Dyanmic file timestamps:

A function or a string can be supplied as the fileTimestamp. This will get the last modified date from the file to use as the lastmod for the pages that match the glob path.

sitemap({
		url: 'http://www.example.com/',
		content: {
			'/content/**/*': {
				fileTimestamp: './src/content.json'
			},
			'/page/*': {
				fileTimestamp: function(path, cb){
					path = path.replace('/page/', '')
					cb('./views/' + path + '.pug')
				}
			}
		},
	})
	.then(console.log)
	.catch(console.error)

Excluding paths:

sitemap({
		url: 'http://www.example.com/',
		exclude: [
			'/admin/**/*',
			'/login'
		],
	})
	.then(console.log)
	.catch(console.error)

Options

  • url: [String] The root domain to be crawled
  • replaceUrl: [String] Replaces the url in the final sitemap
  • content: [Object] Paths to supply tags for glob patterns
  • exclude: [Array] An array of glob patterns to be excluded
  • outputFile: [String] Saves out the sitemap file to path specified
  • log: [Function] Pass a function to handle logs
  • depth: [Number] Set to limit the number of pages crawled
  • pretty: [Boolean/String] Set to prettify XML content

FAQs

Last updated on 12 Apr 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc