Socket
Socket
Sign inDemoInstall

sitemap

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sitemap - npm Package Compare versions

Comparing version 6.0.0 to 6.1.0

api.md

4

CHANGELOG.md
# Changelog
## 6.1.0
- Added back xslUrl option removed in 5.0.0
## 6.0.0

@@ -4,0 +8,0 @@

37

dist/cli.js

@@ -34,3 +34,3 @@ #!/usr/bin/env node

'--gzip': Boolean,
'--h': '--help',
'-h': '--help',
};

@@ -56,13 +56,26 @@ const argv = arg(argSpec);

Options:
--help Print this text
--version Print the version
--validate ensure the passed in file is conforms to the sitemap spec
--index create an index and stream that out, write out sitemaps along the way
--index-base-url base url the sitemaps will be hosted eg. https://example.com/sitemaps/
--limit=45000 set a custom limit to the items per sitemap
--parse Parse fed xml and spit out config
--prepend sitemap.xml < urlsToAdd.json
--gzip compress output
--single-line-json When used with parse, it spits out each entry as json rather
than the whole json.
--help Print this text
--version Print the version
--validate Ensure the passed in file is conforms to the sitemap spec
--index Create an index and stream that out. Writes out sitemaps along the way.
--index-base-url Base url the sitemaps will be hosted eg. https://example.com/sitemaps/
--limit=45000 Set a custom limit to the items per sitemap
--parse Parse fed xml and spit out config
--prepend=sitemap.xml Prepend the streamed in sitemap configs to sitemap.xml
--gzip Compress output
--single-line-json When used with parse, it spits out each entry as json rather than the whole json.
# examples
Generate a sitemap index file as well as sitemaps
npx sitemap --gzip --index --index-base-url https://example.com/path/to/sitemaps/ < listofurls.txt > sitemap-index.xml.gz
Add to a sitemap
npx sitemap --prepend sitemap.xml < listofurls.json
Turn an existing sitemap into configuration understood by the sitemap library
npx sitemap --parse sitemap.xml
Use XMLLib to validate your sitemap (requires xmllib)
npx sitemap --validate sitemap.xml
`);

@@ -69,0 +82,0 @@ }

@@ -12,5 +12,7 @@ /// <reference types="node" />

level?: ErrorLevel;
xslUrl?: string;
}
export declare class SitemapIndexStream extends Transform {
level: ErrorLevel;
xslUrl?: string;
private hasHeadOutput;

@@ -35,3 +37,3 @@ constructor(opts?: SitemapIndexStreamOptions);

*/
export declare function createSitemapsAndIndex({ urls, targetFolder, hostname, sitemapName, sitemapSize, gzip, }: {
export declare function createSitemapsAndIndex({ urls, targetFolder, hostname, sitemapName, sitemapSize, gzip, xslUrl, }: {
urls: (string | SitemapItemLoose)[];

@@ -43,2 +45,3 @@ targetFolder: string;

gzip?: boolean;
xslUrl?: string;
}): Promise<boolean>;

@@ -45,0 +48,0 @@ declare type getSitemapStream = (i: number) => [IndexItem | string, SitemapStream];

@@ -20,3 +20,4 @@ "use strict";

const statPromise = util_1.promisify(fs_1.stat);
const preamble = '<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
const xmlDec = '<?xml version="1.0" encoding="UTF-8"?>';
const sitemapIndexTagStart = '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
const closetag = '</sitemapindex>';

@@ -31,2 +32,3 @@ const defaultStreamOpts = {};

this.level = (_a = opts.level) !== null && _a !== void 0 ? _a : types_1.ErrorLevel.WARN;
this.xslUrl = opts.xslUrl;
}

@@ -36,3 +38,7 @@ _transform(item, encoding, callback) {

this.hasHeadOutput = true;
this.push(preamble);
let stylesheet = '';
if (this.xslUrl) {
stylesheet = sitemap_stream_1.stylesheetInclude(this.xslUrl);
}
this.push(xmlDec + stylesheet + sitemapIndexTagStart);
}

@@ -72,4 +78,4 @@ this.push(sitemap_xml_1.otag(IndexTagNames.sitemap));

*/
async function createSitemapsAndIndex({ urls, targetFolder, hostname, sitemapName = 'sitemap', sitemapSize = 50000, gzip = true, }) {
const indexStream = new SitemapIndexStream();
async function createSitemapsAndIndex({ urls, targetFolder, hostname, sitemapName = 'sitemap', sitemapSize = 50000, gzip = true, xslUrl, }) {
const indexStream = new SitemapIndexStream({ xslUrl });
try {

@@ -92,3 +98,3 @@ const stats = await statPromise(targetFolder);

const ws = fs_1.createWriteStream(targetFolder + '/' + filename);
const sms = new sitemap_stream_1.SitemapStream({ hostname });
const sms = new sitemap_stream_1.SitemapStream({ hostname, xslUrl });
let pipe;

@@ -95,0 +101,0 @@ if (gzip) {

/// <reference types="node" />
import { Transform, TransformOptions, TransformCallback, Readable } from 'stream';
import { SitemapItemLoose, ErrorLevel } from './types';
export declare const stylesheetInclude: (url: string) => string;
export interface NSArgs {

@@ -17,3 +18,3 @@ news: boolean;

xmlns?: NSArgs;
errorHandler?: (error: Error, level: ErrorLevel) => void;
xslUrl?: string;
}

@@ -32,2 +33,3 @@ /**

xmlNS: NSArgs;
xslUrl?: string;
private smiStream;

@@ -34,0 +36,0 @@ lastmodDateOnly: boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const url_1 = require("url");
const stream_1 = require("stream");

@@ -7,5 +8,15 @@ const types_1 = require("./types");

const sitemap_item_stream_1 = require("./sitemap-item-stream");
const preamble = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
const getURLSetNs = ({ news, video, image, xhtml, custom, }) => {
let ns = preamble;
const xmlDec = '<?xml version="1.0" encoding="UTF-8"?>';
exports.stylesheetInclude = (url) => {
// Throws if url is invalid
new url_1.URL(url);
return `<?xml-stylesheet type="text/xsl" href="${url}"?>`;
};
const urlsetTagStart = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
const getURLSetNs = ({ news, video, image, xhtml, custom }, xslURL) => {
let ns = xmlDec;
if (xslURL) {
ns += exports.stylesheetInclude(xslURL);
}
ns += urlsetTagStart;
if (news) {

@@ -56,2 +67,3 @@ ns += ' xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"';

this.xmlNS = opts.xmlns || defaultXMLNS;
this.xslUrl = opts.xslUrl;
}

@@ -61,3 +73,3 @@ _transform(item, encoding, callback) {

this.hasHeadOutput = true;
this.push(getURLSetNs(this.xmlNS));
this.push(getURLSetNs(this.xmlNS, this.xslUrl));
}

@@ -64,0 +76,0 @@ this.smiStream.write(utils_1.validateSMIOptions(utils_1.normalizeURL(item, this.hostname, this.lastmodDateOnly), this.level));

{
"name": "sitemap",
"version": "6.0.0",
"version": "6.1.0",
"description": "Sitemap-generating lib/cli",

@@ -97,2 +97,3 @@ "keywords": [

],
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-member-accessibility": "off",

@@ -142,3 +143,3 @@ "@typescript-eslint/interface-name-prefix": "off",

"dependencies": {
"@types/node": "^13.7.4",
"@types/node": "^13.9.1",
"@types/sax": "^1.2.1",

@@ -149,13 +150,13 @@ "arg": "^4.1.3",

"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/core": "^7.8.7",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3",
"@babel/plugin-proposal-optional-chaining": "^7.8.3",
"@babel/plugin-transform-typescript": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/plugin-transform-typescript": "^7.8.7",
"@babel/preset-env": "^7.8.7",
"@babel/preset-typescript": "^7.8.3",
"@types/jest": "^25.1.3",
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0",
"babel-eslint": "^10.0.3",
"@types/jest": "^25.1.4",
"@typescript-eslint/eslint-plugin": "^2.23.0",
"@typescript-eslint/parser": "^2.23.0",
"babel-eslint": "^10.1.0",
"babel-polyfill": "^6.26.0",

@@ -165,3 +166,3 @@ "concurrently": "^5.1.0",

"eslint-config-prettier": "^6.10.0",
"eslint-plugin-jest": "^23.8.0",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-prettier": "^3.1.2",

@@ -171,3 +172,3 @@ "express": "^4.17.1",

"jest": "^25.1.0",
"lint-staged": "^10.0.7",
"lint-staged": "^10.0.8",
"prettier": "^1.19.1",

@@ -179,3 +180,3 @@ "sort-package-json": "^1.40.0",

"through2-map": "^3.0.0",
"typescript": "^3.8.2"
"typescript": "^3.8.3"
},

@@ -182,0 +183,0 @@ "engines": {

@@ -14,27 +14,8 @@ # sitemap ![MIT License](https://img.shields.io/npm/l/sitemap)[![Build Status](https://travis-ci.org/ekalinin/sitemap.js.svg?branch=master)](https://travis-ci.org/ekalinin/sitemap.js)![Monthly Downloads](https://img.shields.io/npm/dm/sitemap)

- [Installation](#installation)
- [Usage](#usage)
- [CLI](#cli)
- [Example of using sitemap.js with](#example-of-using-sitemapjs-with-express) [express](https://expressjs.com/)
- [Stream writing a sitemap](#stream-writing-a-sitemap)
- [Example of most of the options you can use for sitemap](#example-of-most-of-the-options-you-can-use-for-sitemap)
- [Building just the sitemap index file](#building-just-the-sitemap-index-file)
- [Auto creating sitemap and index files from one large list](#auto-creating-sitemap-and-index-files-from-one-large-list)
- [More](#more)
- [Generate a one time sitemap from a list of urls](#generate-a-one-time-sitemap-from-a-list-of-urls)
- [Example of using sitemap.js with](#serve-a-sitemap-from-a-server-and-periodically-update-it) [express](https://expressjs.com/)
- [Generating more than one sitemap](#create-sitemap-and-index-files-from-one-large-list)
- [Options you can pass](#options-you-can-pass)
- [More](#more)
- [API](#api)
- [SitemapStream](#sitemapstream)
- [XMLToSitemapOptions](#XMLToSitemapOptions)
- [sitemapAndIndexStream](#sitemapandindexstream)
- [SitemapIndexStream](#SitemapIndexStream)
- [createSitemapsAndIndex](#createsitemapsandindex)
- [xmlLint](#xmllint)
- [parseSitemap](#parsesitemap)
- [lineSeparatedURLsToSitemapOptions](#lineseparatedurlstositemapoptions)
- [streamToPromise](#streamtopromise)
- [ObjectStreamToJSON](#objectstreamtojson)
- [SitemapItemStream](#SitemapItemStream)
- [Sitemap Item Options](#sitemap-item-options)
- [SitemapImage](#sitemapimage)
- [VideoItem](#videoitem)
- [LinkItem](#linkitem)
- [NewsItem](#newsitem)
- [License](#license)

@@ -48,60 +29,16 @@

## Usage
## Generate a one time sitemap from a list of urls
## CLI
If you are just looking to take a giant list of URLs and turn it into some sitemaps,
try out our CLI. The cli can also parse, update and validate existing sitemaps.
Just feed the list of urls into sitemap
```sh
npx sitemap < listofurls.txt
npx sitemap < listofurls.txt # `npx sitemap -h` for more examples and a list of options.
```
Or create an index and sitemaps at the same time.
## Serve a sitemap from a server and periodically update it
```sh
npx sitemap --index --index-base-url https://example.com/path/to/sitemaps/ < listofurls.txt > sitemap-index.xml
```
Use this if you have less than 50 thousand urls. See SitemapAndIndexStream for if you have more.
Or validate an existing sitemap (requires libxml)
```sh
npx sitemap --validate sitemap.xml
```
Or take an existing sitemap and turn it into options that can be fed into the libary
```sh
npx sitemap --parse sitemap.xml
```
Or prepend some new urls to an existing sitemap
```sh
npx sitemap --prepend sitemap.xml < listofurls.json # or txt
```
## As a library
```js
const { SitemapStream, streamToPromise } = require('../dist/index')
// Creates a sitemap object given the input configuration with URLs
const sitemap = new SitemapStream({ hostname: 'http://example.com' });
sitemap.write({ url: '/page-1/', changefreq: 'daily', priority: 0.3 })
sitemap.write('/page-2')
sitemap.end()
streamToPromise(sitemap)
.then(sm => console.log(sm.toString()))
.catch(console.error);
```
Resolves to a string containing the XML data
```xml
<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"><url><loc>http://example.com/page-1/</loc><changefreq>daily</changefreq><priority>0.3</priority></url><url><loc>http://example.com/page-2</loc></url></urlset>
```
### Example of using sitemap.js with [express](https://expressjs.com/)
```js
const express = require('express')

@@ -122,2 +59,3 @@ const { SitemapStream, streamToPromise } = require('sitemap')

}
try {

@@ -127,2 +65,3 @@ const smStream = new SitemapStream({ hostname: 'https://example.com/' })

// pipe your entries or directly write them.
smStream.write({ url: '/page-1/', changefreq: 'daily', priority: 0.3 })

@@ -136,3 +75,3 @@ smStream.write({ url: '/page-2/', changefreq: 'monthly', priority: 0.7 })

streamToPromise(pipeline).then(sm => sitemap = sm)
// stream the response
// stream write the response
pipeline.pipe(res).on('error', (e) => {throw e})

@@ -150,56 +89,56 @@ } catch (e) {

### Stream writing a sitemap
## Create sitemap and index files from one large list
The sitemap stream is around 20% faster and only uses ~10% the memory of the traditional interface
If you know you are definitely going to have more than 50,000 urls in your sitemap, you can use this slightly more complex interface to create a new sitemap every 45,000 entries and add that file to a sitemap index.
```javascript
const fs = require('fs');
const { SitemapStream } = require('sitemap')
// external libs provided as example only
const { parser } = require('stream-json/Parser');
const { streamArray } = require('stream-json/streamers/StreamArray');
const { streamValues } = require('stream-json/streamers/StreamValues');
const map = require('through2-map')
```js
const { createReadStream, createWriteStream } = require('fs');
const { resolve } = require('path');
const { createGzip } = require('zlib')
const {
SitemapAndIndexStream,
SitemapStream,
lineSeparatedURLsToSitemapOptions
} = require('sitemap')
// parsing line separated json or JSONStream
const pipeline = fs
.createReadStream("./tests/mocks/perf-data.json.txt"),
.pipe(parser())
.pipe(streamValues())
.pipe(map.obj(chunk => chunk.value))
// SitemapStream does the heavy lifting
// You must provide it with an object stream
.pipe(new SitemapStream());
const sms = new SitemapAndIndexStream({
limit: 10000, // defaults to 45k
// SitemapAndIndexStream will call this user provided function every time
// it needs to create a new sitemap file. You merely need to return a stream
// for it to write the sitemap urls to and the expected url where that sitemap will be hosted
getSitemapStream: (i) => {
const sitemapStream = new SitemapStream();
const path = `./sitemap-${i}.xml`;
// parsing JSON file
const pipeline = fs
.createReadStream("./tests/mocks/perf-data.json")
.pipe(parser())
.pipe(streamArray())
.pipe(map.obj(chunk => chunk.value))
// SitemapStream does the heavy lifting
// You must provide it with an object stream
.pipe(new SitemapStream({ hostname: 'https://example.com/' }))
.pipe(process.stdout)
sitemapStream
.pipe(createGzip()) // compress the output of the sitemap
.pipe(createWriteStream(resolve(path + '.gz'))); // write it to sitemap-NUMBER.xml
//
// coalesce into value for caching
//
let cachedXML
streamToPromise(
fs.createReadStream("./tests/mocks/perf-data.json")
.pipe(parser())
.pipe(streamArray())
.pipe(map.obj(chunk => chunk.value))
.pipe(new SitemapStream({ hostname: 'https://example.com/' }))
.pipe(createGzip())
).then(xmlBuffer => cachedXML = xmlBuffer)
return [new URL(path, 'https://example.com/subdir/').toString(), sitemapStream];
},
});
lineSeparatedURLsToSitemapOptions(
createReadStream('./your-data.json.txt')
)
.pipe(sms)
.pipe(createGzip())
.pipe(createWriteStream(resolve('./sitemap-index.xml.gz')));
```
### Example of most of the options you can use for sitemap
### Options you can pass
```js
const { SitemapStream, streamToPromise } = require('sitemap');
const smStream = new SitemapStream({ hostname: 'http://www.mywebsite.com' })
const smStream = new SitemapStream({
hostname: 'http://www.mywebsite.com',
xslUrl: "https://example.com/style.xsl",
lastmodDateOnly: false, // print date not time
xmlns: { // trim the xml namespace
news: true, // flip to false to omit the xml namespace for news
xhtml: true,
image: true,
video: true,
}
})
// coalesce stream to value

@@ -212,16 +151,7 @@ // alternatively you can pipe to another stream

changefreq: 'weekly',
priority: 0.8,
lastmodfile: 'app/assets/page1.html'
priority: 0.8, // A hint to the crawler that it should prioritize this over items less than 0.8
})
smStream.write({
url: '/page2',
changefreq: 'weekly',
priority: 0.8,
/* useful to monitor template content files instead of generated static files */
lastmodfile: 'app/templates/page2.hbs'
})
// each sitemap entry supports many options
// See [Sitemap Item Options](#sitemap-item-options) below for details
// See [Sitemap Item Options](./api.md#sitemap-item-options) below for details
smStream.write({

@@ -280,42 +210,2 @@ url: 'http://test.com/page-1/',

### Building just the sitemap index file
The sitemap index file merely points to other sitemaps
```js
const { buildSitemapIndex } = require('sitemap')
const smi = buildSitemapIndex({
urls: ['https://example.com/sitemap1.xml', 'https://example.com/sitemap2.xml'],
xslUrl: 'https://example.com/style.xsl' // optional
})
```
### Auto creating sitemap and index files from one large list
```js
const limit = 45000
const baseURL = 'https://example.com/subdir/'
const sms = new SitemapAndIndexStream({
limit, // defaults to 45k
getSitemapStream: (i) => {
const sm = new SitemapStream();
const path = `./sitemap-${i}.xml`;
if (argv['--gzip']) {
sm.pipe(createGzip()).pipe(createWriteStream(path));
} else {
sm.pipe(createWriteStream(path));
}
return [new URL(path, baseURL).toString(), sm];
},
});
let oStream = lineSeparatedURLsToSitemapOptions(
pickStreamOrArg(argv)
).pipe(sms);
if (argv['--gzip']) {
oStream = oStream.pipe(createGzip());
}
oStream.pipe(process.stdout);
```
## More

@@ -327,275 +217,6 @@

### SitemapStream
Full API docs can be found [here](./api.md)
A [Transform](https://nodejs.org/api/stream.html#stream_implementing_a_transform_stream) for turning a [Readable stream](https://nodejs.org/api/stream.html#stream_readable_streams) of either [SitemapItemOptions](#sitemap-item-options) or url strings into a Sitemap. The readable stream it transforms **must** be in object mode.
```javascript
const { SitemapStream } = require('sitemap')
const sms = new SitemapStream({
hostname: 'https://example.com', // optional only necessary if your paths are relative
lastmodDateOnly: false // defaults to false, flip to true for baidu
xmlNS: { // XML namespaces to turn on - all by default
news: true,
xhtml: true,
image: true,
video: true,
// custom: ['xmlns:custom="https://example.com"']
}
})
const readable = // a readable stream of objects
readable.pipe(sms).pipe(process.stdout)
```
### XMLToSitemapOptions
Takes a stream of xml and transforms it into a stream of ISitemapOptions.
Use this to parse existing sitemaps into config options compatible with this library
```javascript
const { createReadStream, createWriteStream } = require('fs');
const { XMLToISitemapOptions, ObjectStreamToJSON } = require('sitemap');
createReadStream('./some/sitemap.xml')
// turn the xml into sitemap option item options
.pipe(new XMLToISitemapOptions())
// convert the object stream to JSON
.pipe(new ObjectStreamToJSON())
// write the library compatible options to disk
.pipe(createWriteStream('./sitemapOptions.json'))
```
### SitemapIndexStream
Writes a sitemap index when given a stream urls.
```js
/**
* writes the following
* <?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://example.com/</loc>
</sitemap>
<sitemap>
<loc>https://example.com/2</loc>
</sitemap>
*/
const smis = new SitemapIndexStream({level: 'warn'})
smis.write({url: 'https://example.com/'})
smis.write({url: 'https://example.com/2'})
smis.pipe(writestream)
smis.end()
```
### sitemapAndIndexStream
Use this to take a stream which may go over the max of 50000 items and split it into an index and sitemaps.
SitemapAndIndexStream consumes a stream of urls and streams out index entries while writing individual urls to the streams you give it.
Provide it with a function which when provided with a index returns a url where the sitemap will ultimately be hosted and a stream to write the current sitemap to. This function will be called everytime the next item in the stream would exceed the provided limit.
```js
const sms = new SitemapAndIndexStream({
limit, // defaults to 45k
getSitemapStream: (i) => {
const sm = new SitemapStream();
const path = `./sitemap-${i}.xml`;
if (argv['--gzip']) {
sm.pipe(createGzip()).pipe(createWriteStream(path));
} else {
sm.pipe(createWriteStream(path));
}
return [new URL(path, baseURL).toString(), sm];
},
});
let oStream = lineSeparatedURLsToSitemapOptions(
pickStreamOrArg(argv)
).pipe(sms);
if (argv['--gzip']) {
oStream = oStream.pipe(createGzip());
}
oStream.pipe(process.stdout);
```
### createSitemapsAndIndex
Create several sitemaps and an index automatically from a list of urls. __deprecated__
```js
const { createSitemapsAndIndex } = require('sitemap')
createSitemapsAndIndex({
urls: [/* list of urls */],
targetFolder: 'absolute path to target folder',
hostname: 'http://example.com',
cacheTime: 600,
sitemapName: 'sitemap',
sitemapSize: 50000, // number of urls to allow in each sitemap
gzip: true, // whether to gzip the files
})
```
### xmlLint
Resolve or reject depending on whether the passed in xml is a valid sitemap.
This is just a wrapper around the xmlLint command line tool and thus requires
xmlLint.
```js
const { createReadStream } = require('fs')
const { xmlLint } = require('sitemap')
xmlLint(createReadStream('./example.xml')).then(
() => console.log('xml is valid'),
([err, stderr]) => console.error('xml is invalid', stderr)
)
```
### parseSitemap
Read xml and resolve with the configuration that would produce it or reject with
an error
```js
const { createReadStream } = require('fs')
const { parseSitemap, createSitemap } = require('sitemap')
parseSitemap(createReadStream('./example.xml')).then(
// produces the same xml
// you can, of course, more practically modify it or store it
(xmlConfig) => console.log(createSitemap(xmlConfig).toString()),
(err) => console.log(err)
)
```
### lineSeparatedURLsToSitemapOptions
Takes a stream of urls or sitemapoptions likely from fs.createReadStream('./path') and returns an object stream of sitemap items.
### streamToPromise
Takes a stream returns a promise that resolves when stream emits finish.
```javascript
const { streamToPromise, SitemapStream } = require('sitemap')
const sitemap = new SitemapStream({ hostname: 'http://example.com' });
sitemap.write({ url: '/page-1/', changefreq: 'daily', priority: 0.3 })
sitemap.end()
streamToPromise(sitemap).then(buffer => console.log(buffer.toString())) // emits the full sitemap
```
### ObjectStreamToJSON
A Transform that converts a stream of objects into a JSON Array or a line separated stringified JSON.
- @param [lineSeparated=false] whether to separate entries by a new line or comma
```javascript
const stream = Readable.from([{a: 'b'}])
.pipe(new ObjectStreamToJSON())
.pipe(process.stdout)
stream.end()
// prints {"a":"b"}
```
### SitemapItemStream
Takes a stream of SitemapItemOptions and spits out xml for each
```js
// writes <url><loc>https://example.com</loc><url><url><loc>https://example.com/2</loc><url>
const smis = new SitemapItemStream({level: 'warn'})
smis.pipe(writestream)
smis.write({url: 'https://example.com', img: [], video: [], links: []})
smis.write({url: 'https://example.com/2', img: [], video: [], links: []})
smis.end()
```
### Sitemap Item Options
|Option|Type|eg|Description|
|------|----|--|-----------|
|url|string|`http://example.com/some/path`|The only required property for every sitemap entry|
|lastmod|string|'2019-07-29' or '2019-07-22T05:58:37.037Z'|When the page we as last modified use the W3C Datetime ISO8601 subset <https://www.sitemaps.org/protocol.html#xmlTagDefinitions>|
|changefreq|string|'weekly'|How frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page. Please note that the value of this tag is considered a hint and not a command. See <https://www.sitemaps.org/protocol.html#xmlTagDefinitions> for the acceptable values|
|priority|number|0.6|The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. This value does not affect how your pages are compared to pages on other sites—it only lets the search engines know which pages you deem most important for the crawlers. The default priority of a page is 0.5. <https://www.sitemaps.org/protocol.html#xmlTagDefinitions>|
|img|object[]|see [#ISitemapImage](#ISitemapImage)|<https://support.google.com/webmasters/answer/178636?hl=en&ref_topic=4581190>|
|video|object[]|see [#IVideoItem](#IVideoItem)|<https://support.google.com/webmasters/answer/80471?hl=en&ref_topic=4581190>|
|links|object[]|see [#ILinkItem](#ILinkItem)|Tell search engines about localized versions <https://support.google.com/webmasters/answer/189077>|
|news|object|see [#INewsItem](#INewsItem)|<https://support.google.com/webmasters/answer/74288?hl=en&ref_topic=4581190>|
|ampLink|string|`http://ampproject.org/article.amp.html`||
|cdata|boolean|true|wrap url in cdata xml escape|
### SitemapImage
Sitemap image
<https://support.google.com/webmasters/answer/178636?hl=en&ref_topic=4581190>
|Option|Type|eg|Description|
|------|----|--|-----------|
|url|string|`http://example.com/image.jpg`|The URL of the image.|
|caption|string - optional|'Here we did the stuff'|The caption of the image.|
|title|string - optional|'Star Wars EP IV'|The title of the image.|
|geoLocation|string - optional|'Limerick, Ireland'|The geographic location of the image.|
|license|string - optional|`http://example.com/license.txt`|A URL to the license of the image.|
### VideoItem
Sitemap video. <https://support.google.com/webmasters/answer/80471?hl=en&ref_topic=4581190>
|Option|Type|eg|Description|
|------|----|--|-----------|
|thumbnail_loc|string|`"https://rtv3-img-roosterteeth.akamaized.net/store/0e841100-289b-4184-ae30-b6a16736960a.jpg/sm/thumb3.jpg"`|A URL pointing to the video thumbnail image file|
|title|string|'2018:E6 - GoldenEye: Source'|The title of the video. |
|description|string|'We play gun game in GoldenEye: Source with a good friend of ours. His name is Gruchy. Dan Gruchy.'|A description of the video. Maximum 2048 characters. |
|content_loc|string - optional|`"http://streamserver.example.com/video123.mp4"`|A URL pointing to the actual video media file. Should be one of the supported formats. HTML is not a supported format. Flash is allowed, but no longer supported on most mobile platforms, and so may be indexed less well. Must not be the same as the `<loc>` URL.|
|player_loc|string - optional|`"https://roosterteeth.com/embed/rouletsplay-2018-goldeneye-source"`|A URL pointing to a player for a specific video. Usually this is the information in the src element of an `<embed>` tag. Must not be the same as the `<loc>` URL|
|'player_loc:autoplay'|string - optional|'ap=1'|a string the search engine can append as a query param to enable automatic playback|
|duration|number - optional| 600| duration of video in seconds|
|expiration_date| string - optional|"2012-07-16T19:20:30+08:00"|The date after which the video will no longer be available|
|view_count|number - optional|'21000000000'|The number of times the video has been viewed.|
|publication_date| string - optional|"2018-04-27T17:00:00.000Z"|The date the video was first published, in W3C format.|
|category|string - optional|"Baking"|A short description of the broad category that the video belongs to. This is a string no longer than 256 characters.|
|restriction|string - optional|"IE GB US CA"|Whether to show or hide your video in search results from specific countries.|
|restriction:relationship| string - optional|"deny"||
|gallery_loc| string - optional|`"https://roosterteeth.com/series/awhu"`|Currently not used.|
|gallery_loc:title|string - optional|"awhu series page"|Currently not used.|
|price|string - optional|"1.99"|The price to download or view the video. Omit this tag for free videos.|
|price:resolution|string - optional|"HD"|Specifies the resolution of the purchased version. Supported values are hd and sd.|
|price:currency| string - optional|"USD"|currency [Required] Specifies the currency in ISO 4217 format.|
|price:type|string - optional|"rent"|type [Optional] Specifies the purchase option. Supported values are rent and own. |
|uploader|string - optional|"GrillyMcGrillerson"|The video uploader's name. Only one <video:uploader> is allowed per video. String value, max 255 characters.|
|platform|string - optional|"tv"|Whether to show or hide your video in search results on specified platform types. This is a list of space-delimited platform types. See <https://support.google.com/webmasters/answer/80471?hl=en&ref_topic=4581190> for more detail|
|platform:relationship|string 'Allow'\|'Deny' - optional|'Allow'||
|id|string - optional|||
|tag|string[] - optional|['Baking']|An arbitrary string tag describing the video. Tags are generally very short descriptions of key concepts associated with a video or piece of content.|
|rating|number - optional|2.5|The rating of the video. Supported values are float numbers|
|family_friendly|string 'YES'\|'NO' - optional|'YES'||
|requires_subscription|string 'YES'\|'NO' - optional|'YES'|Indicates whether a subscription (either paid or free) is required to view the video. Allowed values are yes or no.|
|live|string 'YES'\|'NO' - optional|'NO'|Indicates whether the video is a live stream. Supported values are yes or no.|
### ILinkItem
<https://support.google.com/webmasters/answer/189077>
|Option|Type|eg|Description|
|------|----|--|-----------|
|lang|string|'en'||
|url|string|`'http://example.com/en/'`||
### NewsItem
<https://support.google.com/webmasters/answer/74288?hl=en&ref_topic=4581190>
|Option|Type|eg|Description|
|------|----|--|-----------|
|access|string - 'Registration' \| 'Subscription'| 'Registration' - optional||
|publication| object|see following options||
|publication['name']| string|'The Example Times'|The `<name>` is the name of the news publication. It must exactly match the name as it appears on your articles on news.google.com, except for anything in parentheses.|
|publication['language']|string|'en'|The `<language>` is the language of your publication. Use an ISO 639 language code (2 or 3 letters).|
|genres|string - optional|'PressRelease, Blog'||
|publication_date|string|'2008-12-23'|Article publication date in W3C format, using either the "complete date" (YYYY-MM-DD) format or the "complete date plus hours, minutes, and seconds"|
|title|string|'Companies A, B in Merger Talks'|The title of the news article.|
|keywords|string - optional|"business, merger, acquisition, A, B"||
|stock_tickers|string - optional|"NASDAQ:A, NASDAQ:B"||
## License
See [LICENSE](https://github.com/ekalinin/sitemap.js/blob/master/LICENSE) file.
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