sitemap-creator
Crawls a site and creates sitemaps based on glob patterns
Last updated 2 years ago by ken85rose .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install sitemap-creator 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.3                                ...           latest (2 years ago)

9 Versions

  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 1
Last Month 15
Dependencies (4)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |