Comparing version 6.4.0 to 7.0.0
21
api.md
@@ -90,7 +90,7 @@ # API | ||
sitemapStream | ||
const ws = sitemapStream | ||
.pipe(createGzip()) // compress the output of the sitemap | ||
.pipe(createWriteStream(resolve(path + '.gz'))); // write it to sitemap-NUMBER.xml | ||
return [new URL(path, 'https://example.com/subdir/').toString(), sitemapStream]; | ||
return [new URL(path, 'https://example.com/subdir/').toString(), sitemapStream, ws]; | ||
}, | ||
@@ -107,19 +107,2 @@ }); | ||
## 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 | ||
}) | ||
``` | ||
## SitemapIndexStream | ||
@@ -126,0 +109,0 @@ |
# Changelog | ||
## 7.0.0 | ||
### [BREAKING] | ||
- dropped support for Node 10, added support for Node 16 | ||
- removed deprecated createSitemapsAndIndex. use SitemapAndIndexStream or simpleSitemapAndIndex | ||
- dropped deprecated `getSitemapStream` option for SitemapAndIndexStream that does not return a write stream | ||
- fixed invalid documentation for #357 | ||
### non-breaking | ||
- Added option to simplesitemap `publicBasePath`: allows the user to set the location of sitemap files hosted on the site fixes [#359] | ||
- bumped dependencies | ||
## 6.4.0 | ||
@@ -4,0 +18,0 @@ |
@@ -114,9 +114,10 @@ #!/usr/bin/env node | ||
const path = `./sitemap-${i}.xml`; | ||
let ws; | ||
if (argv['--gzip']) { | ||
sm.pipe(zlib_1.createGzip()).pipe(fs_1.createWriteStream(path)); | ||
ws = sm.pipe(zlib_1.createGzip()).pipe(fs_1.createWriteStream(path)); | ||
} | ||
else { | ||
sm.pipe(fs_1.createWriteStream(path)); | ||
ws = sm.pipe(fs_1.createWriteStream(path)); | ||
} | ||
return [new url_1.URL(path, baseURL).toString(), sm]; | ||
return [new url_1.URL(path, baseURL).toString(), sm, ws]; | ||
}, | ||
@@ -123,0 +124,0 @@ }); |
@@ -7,3 +7,3 @@ /*! | ||
export { SitemapItemStream, SitemapItemStreamOptions, } from './lib/sitemap-item-stream'; | ||
export { IndexTagNames, SitemapIndexStream, SitemapIndexStreamOptions, createSitemapsAndIndex, SitemapAndIndexStream, SitemapAndIndexStreamOptions, } from './lib/sitemap-index-stream'; | ||
export { IndexTagNames, SitemapIndexStream, SitemapIndexStreamOptions, SitemapAndIndexStream, SitemapAndIndexStreamOptions, } from './lib/sitemap-index-stream'; | ||
export { streamToPromise, SitemapStream, SitemapStreamOptions, } from './lib/sitemap-stream'; | ||
@@ -10,0 +10,0 @@ export * from './lib/errors'; |
@@ -13,3 +13,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.simpleSitemapAndIndex = exports.ObjectStreamToJSON = exports.XMLToSitemapItemStream = exports.parseSitemap = exports.xmlLint = exports.ReadlineStream = exports.normalizeURL = exports.validateSMIOptions = exports.mergeStreams = exports.lineSeparatedURLsToSitemapOptions = exports.SitemapStream = exports.streamToPromise = exports.SitemapAndIndexStream = exports.createSitemapsAndIndex = exports.SitemapIndexStream = exports.IndexTagNames = exports.SitemapItemStream = void 0; | ||
exports.simpleSitemapAndIndex = exports.ObjectStreamToJSON = exports.XMLToSitemapItemStream = exports.parseSitemap = exports.xmlLint = exports.ReadlineStream = exports.normalizeURL = exports.validateSMIOptions = exports.mergeStreams = exports.lineSeparatedURLsToSitemapOptions = exports.SitemapStream = exports.streamToPromise = exports.SitemapAndIndexStream = exports.SitemapIndexStream = exports.IndexTagNames = exports.SitemapItemStream = void 0; | ||
/*! | ||
@@ -25,3 +25,2 @@ * Sitemap | ||
Object.defineProperty(exports, "SitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapIndexStream; } }); | ||
Object.defineProperty(exports, "createSitemapsAndIndex", { enumerable: true, get: function () { return sitemap_index_stream_1.createSitemapsAndIndex; } }); | ||
Object.defineProperty(exports, "SitemapAndIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapAndIndexStream; } }); | ||
@@ -28,0 +27,0 @@ var sitemap_stream_1 = require("./lib/sitemap-stream"); |
@@ -23,28 +23,3 @@ /// <reference types="node" /> | ||
} | ||
/** | ||
* Shortcut for `new SitemapIndex (...)`. | ||
* Create several sitemaps and an index automatically from a list of urls | ||
* | ||
* @deprecated Use SitemapAndIndexStream | ||
* @param {Object} conf | ||
* @param {String|Array} conf.urls | ||
* @param {String} conf.targetFolder where do you want the generated index and maps put | ||
* @param {String} conf.hostname required for index file, will also be used as base url for sitemap items | ||
* @param {String} conf.sitemapName what do you want to name the files it generats | ||
* @param {Number} conf.sitemapSize maximum number of entries a sitemap should have before being split | ||
* @param {Boolean} conf.gzip whether to gzip the files (defaults to true) | ||
* @return {SitemapIndex} | ||
*/ | ||
export declare function createSitemapsAndIndex({ urls, targetFolder, hostname, sitemapName, sitemapSize, gzip, xslUrl, }: { | ||
urls: (string | SitemapItemLoose)[]; | ||
targetFolder: string; | ||
hostname?: string; | ||
sitemapName?: string; | ||
sitemapSize?: number; | ||
gzip?: boolean; | ||
xslUrl?: string; | ||
}): Promise<boolean>; | ||
declare type getSitemapStream = (i: number) => [IndexItem | string, SitemapStream, WriteStream]; | ||
/** @deprecated */ | ||
declare type getSitemapStreamDeprecated = (i: number) => [IndexItem | string, SitemapStream]; | ||
export interface SitemapAndIndexStreamOptions extends SitemapIndexStreamOptions { | ||
@@ -55,7 +30,2 @@ level?: ErrorLevel; | ||
} | ||
export interface SitemapAndIndexStreamOptionsDeprecated extends SitemapIndexStreamOptions { | ||
level?: ErrorLevel; | ||
limit?: number; | ||
getSitemapStream: getSitemapStreamDeprecated; | ||
} | ||
export declare class SitemapAndIndexStream extends SitemapIndexStream { | ||
@@ -68,8 +38,2 @@ private i; | ||
private limit; | ||
/** | ||
* @deprecated this version does not properly wait for everything to write before resolving | ||
* pass a 3rd param in your return from getSitemapStream that is the writeable stream | ||
* to remove this warning | ||
*/ | ||
constructor(opts: SitemapAndIndexStreamOptionsDeprecated); | ||
constructor(opts: SitemapAndIndexStreamOptions); | ||
@@ -76,0 +40,0 @@ _writeSMI(item: SitemapItemLoose): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SitemapAndIndexStream = exports.createSitemapsAndIndex = exports.SitemapIndexStream = exports.IndexTagNames = void 0; | ||
const util_1 = require("util"); | ||
const url_1 = require("url"); | ||
const fs_1 = require("fs"); | ||
const zlib_1 = require("zlib"); | ||
exports.SitemapAndIndexStream = exports.SitemapIndexStream = exports.IndexTagNames = void 0; | ||
const stream_1 = require("stream"); | ||
const types_1 = require("./types"); | ||
const errors_1 = require("./errors"); | ||
const utils_1 = require("./utils"); | ||
const sitemap_stream_1 = require("./sitemap-stream"); | ||
@@ -20,3 +14,2 @@ const sitemap_xml_1 = require("./sitemap-xml"); | ||
})(IndexTagNames = exports.IndexTagNames || (exports.IndexTagNames = {})); | ||
const statPromise = util_1.promisify(fs_1.stat); | ||
const xmlDec = '<?xml version="1.0" encoding="UTF-8"?>'; | ||
@@ -63,55 +56,2 @@ const sitemapIndexTagStart = '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; | ||
exports.SitemapIndexStream = SitemapIndexStream; | ||
/** | ||
* Shortcut for `new SitemapIndex (...)`. | ||
* Create several sitemaps and an index automatically from a list of urls | ||
* | ||
* @deprecated Use SitemapAndIndexStream | ||
* @param {Object} conf | ||
* @param {String|Array} conf.urls | ||
* @param {String} conf.targetFolder where do you want the generated index and maps put | ||
* @param {String} conf.hostname required for index file, will also be used as base url for sitemap items | ||
* @param {String} conf.sitemapName what do you want to name the files it generats | ||
* @param {Number} conf.sitemapSize maximum number of entries a sitemap should have before being split | ||
* @param {Boolean} conf.gzip whether to gzip the files (defaults to true) | ||
* @return {SitemapIndex} | ||
*/ | ||
async function createSitemapsAndIndex({ urls, targetFolder, hostname, sitemapName = 'sitemap', sitemapSize = 50000, gzip = true, xslUrl, }) { | ||
const indexStream = new SitemapIndexStream({ xslUrl }); | ||
try { | ||
const stats = await statPromise(targetFolder); | ||
if (!stats.isDirectory()) { | ||
throw new errors_1.UndefinedTargetFolder(); | ||
} | ||
} | ||
catch (e) { | ||
throw new errors_1.UndefinedTargetFolder(); | ||
} | ||
const indexWS = fs_1.createWriteStream(targetFolder + '/' + sitemapName + '-index.xml'); | ||
indexStream.pipe(indexWS); | ||
const smPromises = utils_1.chunk(urls, sitemapSize).map((chunk, idx) => { | ||
return new Promise((resolve, reject) => { | ||
const extension = '.xml' + (gzip ? '.gz' : ''); | ||
const filename = sitemapName + '-' + idx + extension; | ||
indexStream.write(new url_1.URL(filename, hostname).toString()); | ||
const ws = fs_1.createWriteStream(targetFolder + '/' + filename); | ||
const sms = new sitemap_stream_1.SitemapStream({ hostname, xslUrl }); | ||
let pipe; | ||
if (gzip) { | ||
pipe = sms.pipe(zlib_1.createGzip()).pipe(ws); | ||
} | ||
else { | ||
pipe = sms.pipe(ws); | ||
} | ||
chunk.forEach((smi) => sms.write(smi)); | ||
sms.end(); | ||
pipe.on('finish', () => resolve(true)); | ||
pipe.on('error', (e) => reject(e)); | ||
}); | ||
}); | ||
return Promise.all(smPromises).then(() => { | ||
indexStream.end(); | ||
return true; | ||
}); | ||
} | ||
exports.createSitemapsAndIndex = createSitemapsAndIndex; | ||
// const defaultSIStreamOpts: SitemapAndIndexStreamOptions = {}; | ||
@@ -118,0 +58,0 @@ class SitemapAndIndexStream extends SitemapIndexStream { |
import { Readable } from 'stream'; | ||
import { SitemapItemLoose } from './types'; | ||
export declare const simpleSitemapAndIndex: ({ hostname, sitemapHostname, sourceData, destinationDir, limit, gzip, }: { | ||
/** | ||
* | ||
* @param {object} options - | ||
* @param {string} options.hostname - The hostname for all URLs | ||
* @param {string} [options.sitemapHostname] - The hostname for the sitemaps if different than hostname | ||
* @param {SitemapItemLoose[] | string | Readable | string[]} options.sourceData - The urls you want to make a sitemap out of. | ||
* @param {string} options.destinationDir - where to write the sitemaps and index | ||
* @param {string} [options.publicBasePath] - where the sitemaps are relative to the hostname. Defaults to root. | ||
* @param {number} [options.limit] - how many URLs to write before switching to a new file. Defaults to 50k | ||
* @param {boolean} [options.gzip] - whether to compress the written files. Defaults to true | ||
* @returns {Promise<void>} an empty promise that resolves when everything is done | ||
*/ | ||
export declare const simpleSitemapAndIndex: ({ hostname, sitemapHostname, sourceData, destinationDir, limit, gzip, publicBasePath, }: { | ||
hostname: string; | ||
@@ -8,2 +20,3 @@ sitemapHostname?: string | undefined; | ||
destinationDir: string; | ||
publicBasePath?: string | undefined; | ||
limit?: number | undefined; | ||
@@ -10,0 +23,0 @@ gzip?: boolean | undefined; |
@@ -12,2 +12,14 @@ "use strict"; | ||
const pipeline = util_1.promisify(stream_1.pipeline); | ||
/** | ||
* | ||
* @param {object} options - | ||
* @param {string} options.hostname - The hostname for all URLs | ||
* @param {string} [options.sitemapHostname] - The hostname for the sitemaps if different than hostname | ||
* @param {SitemapItemLoose[] | string | Readable | string[]} options.sourceData - The urls you want to make a sitemap out of. | ||
* @param {string} options.destinationDir - where to write the sitemaps and index | ||
* @param {string} [options.publicBasePath] - where the sitemaps are relative to the hostname. Defaults to root. | ||
* @param {number} [options.limit] - how many URLs to write before switching to a new file. Defaults to 50k | ||
* @param {boolean} [options.gzip] - whether to compress the written files. Defaults to true | ||
* @returns {Promise<void>} an empty promise that resolves when everything is done | ||
*/ | ||
const simpleSitemapAndIndex = async ({ hostname, sitemapHostname = hostname, // if different | ||
@@ -17,3 +29,3 @@ /** | ||
*/ | ||
sourceData, destinationDir, limit = 50000, gzip = true, }) => { | ||
sourceData, destinationDir, limit = 50000, gzip = true, publicBasePath = './', }) => { | ||
await fs_1.promises.mkdir(destinationDir, { recursive: true }); | ||
@@ -28,2 +40,6 @@ const sitemapAndIndexStream = new index_1.SitemapAndIndexStream({ | ||
const writePath = path_1.resolve(destinationDir, path + (gzip ? '.gz' : '')); | ||
if (!publicBasePath.endsWith('/')) { | ||
publicBasePath += '/'; | ||
} | ||
const publicPath = path_1.normalize(publicBasePath + path); | ||
let pipeline; | ||
@@ -39,3 +55,3 @@ if (gzip) { | ||
return [ | ||
new url_1.URL(`${path}${gzip ? '.gz' : ''}`, sitemapHostname).toString(), | ||
new url_1.URL(`${publicPath}${gzip ? '.gz' : ''}`, sitemapHostname).toString(), | ||
sitemapStream, | ||
@@ -42,0 +58,0 @@ pipeline, |
{ | ||
"name": "sitemap", | ||
"version": "6.4.0", | ||
"version": "7.0.0", | ||
"description": "Sitemap-generating lib/cli", | ||
@@ -34,7 +34,3 @@ "keywords": [ | ||
"test:typecheck": "tsc", | ||
"test:xmllint": "if which xmllint; then npm run test:schema; else echo 'skipping xml tests. xmllint not installed'; fi", | ||
"watch": "concurrently \"npm:watch:*\"", | ||
"watch:eslint": "eslint -w lib/* ./cli.ts", | ||
"watch:jest": "jest --watch ./tests/sitemap*", | ||
"watch:tsc": "tsc -w" | ||
"test:xmllint": "if which xmllint; then npm run test:schema; else echo 'skipping xml tests. xmllint not installed'; fi" | ||
}, | ||
@@ -74,3 +70,3 @@ "husky": { | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier/@typescript-eslint", | ||
"prettier", | ||
"plugin:prettier/recommended" | ||
@@ -160,3 +156,3 @@ ], | ||
"dependencies": { | ||
"@types/node": "^14.14.28", | ||
"@types/node": "^15.0.1", | ||
"@types/sax": "^1.2.1", | ||
@@ -167,19 +163,18 @@ "arg": "^5.0.0", | ||
"devDependencies": { | ||
"@babel/core": "^7.12.16", | ||
"@babel/plugin-proposal-class-properties": "^7.12.13", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13", | ||
"@babel/plugin-proposal-optional-chaining": "^7.12.16", | ||
"@babel/plugin-transform-typescript": "^7.12.16", | ||
"@babel/preset-env": "^7.12.16", | ||
"@babel/preset-typescript": "^7.12.16", | ||
"@types/jest": "^26.0.20", | ||
"@typescript-eslint/eslint-plugin": "^4.15.1", | ||
"@typescript-eslint/parser": "^4.15.1", | ||
"@babel/core": "^7.14.0", | ||
"@babel/plugin-proposal-class-properties": "^7.13.0", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.13.8", | ||
"@babel/plugin-proposal-optional-chaining": "^7.13.12", | ||
"@babel/plugin-transform-typescript": "^7.13.0", | ||
"@babel/preset-env": "^7.14.0", | ||
"@babel/preset-typescript": "^7.13.0", | ||
"@types/jest": "^26.0.23", | ||
"@typescript-eslint/eslint-plugin": "^4.22.0", | ||
"@typescript-eslint/parser": "^4.22.0", | ||
"babel-eslint": "^10.1.0", | ||
"babel-polyfill": "^6.26.0", | ||
"concurrently": "^5.3.0", | ||
"eslint": "^7.20.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-jest": "^24.1.5", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"eslint": "^7.25.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-jest": "^24.3.6", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"express": "^4.17.1", | ||
@@ -190,3 +185,3 @@ "husky": "^4.3.8", | ||
"prettier": "^2.2.1", | ||
"sort-package-json": "^1.48.1", | ||
"sort-package-json": "^1.49.0", | ||
"source-map": "~0.7.3", | ||
@@ -196,6 +191,6 @@ "stats-lite": "^2.2.0", | ||
"through2-map": "^3.0.0", | ||
"typescript": "^4.1.5" | ||
"typescript": "^4.2.4" | ||
}, | ||
"engines": { | ||
"node": ">=10.3.0", | ||
"node": ">=12.0.0", | ||
"npm": ">=5.6.0" | ||
@@ -202,0 +197,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27
3
157361
2757
+ Added@types/node@15.14.9(transitive)
- Removed@types/node@14.18.63(transitive)
Updated@types/node@^15.0.1