{"name":"sitemap","version":"8.0.2","keywords":["sitemap","sitemap.xml"],"author":{"name":"Eugene Kalinin","email":"e.v.kalinin@gmail.com"},"license":"MIT","_id":"sitemap@8.0.2","maintainers":[{"name":"ekalinin","email":"e.v.kalinin@gmail.com"},{"name":"derduher","email":"patrick.weygand@gmail.com"}],"homepage":"https://github.com/ekalinin/sitemap.js#readme","bugs":{"url":"https://github.com/ekalinin/sitemap.js/issues"},"bin":{"sitemap":"dist/cli.js"},"dist":{"shasum":"27bddb5fc2c61a1cf8f0194674cd89d762c9f5ae","tarball":"http://registry-npm.ywwl.com/sitemap/download/sitemap-8.0.2.tgz","fileCount":38,"integrity":"sha512-LwktpJcyZDoa0IL6KT++lQ53pbSrx2c9ge41/SeLTyqy2XUNA6uR4+P9u5IVo5lPeL2arAcOKn1aZAxoYbCKlQ==","signatures":[{"sig":"MEQCICpT8oE12yM1a8PQM7uAB4ukA6XwvEav72OPdLqAB/b7AiAQaOV3zRvGMXZ4LypA5oyAt8FWh8d9RSSg/F9FmCftHg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":255348,"size":60016,"noattachment":false,"key":"/sitemap/-/sitemap-8.0.2.tgz"},"jest":{"collectCoverage":true,"coverageThreshold":{"global":{"lines":73,"branches":65,"functions":86,"statements":73}},"collectCoverageFrom":["lib/**/*.ts","!lib/**/*.d.ts","!lib/xmllint.ts","!node_modules/"]},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"npm":">=6.0.0","node":">=14.0.0"},"gitHead":"b16e03eb12bf433b77cafeb593a5bdc61ddc5665","scripts":{"test":"eslint lib/* ./cli.ts && tsc && jest ./tests/sitemap*","build":"tsc","prepare":"husky install","test:full":"eslint lib/* ./cli.ts && tsc && jest && npm run test:xmllint","test:perf":"node ./tests/perf.js","test:schema":"node tests/alltags.js | xmllint --schema schema/all.xsd --noout -","test:xmllint":"if which xmllint; then npm run test:schema; else echo 'skipping xml tests. xmllint not installed'; fi","prepublishOnly":"rm -rf dist && npm run test","test:typecheck":"tsc"},"_npmUser":{"name":"derduher","email":"patrick.weygand@gmail.com"},"repository":{"url":"git://github.com/ekalinin/sitemap.js.git","type":"git"},"_npmVersion":"11.6.2","description":"Sitemap-generating lib/cli","directories":{"lib":"lib","test":"tests"},"lint-staged":{"package.json":["sort-package-json"],"{lib,tests}/**/*.ts":["eslint --fix","prettier --write"]},"_nodeVersion":"24.10.0","dependencies":{"arg":"^5.0.0","sax":"^1.4.1","@types/sax":"^1.2.1","@types/node":"^17.0.5"},"eslintConfig":{"env":{"es6":true,"jest":true,"node":true},"rules":{"indent":"off","no-console":0,"no-unused-vars":0,"no-case-declarations":0,"no-dupe-class-members":"off","lines-between-class-members":["error","always",{"exceptAfterSingleLine":true}],"padding-line-between-statements":["error",{"next":"multiline-expression","prev":"multiline-expression","blankLine":"always"}],"@typescript-eslint/ban-ts-comment":["error",{"ts-expect-error":"allow-with-description"}],"@typescript-eslint/no-unused-vars":["error",{"args":"none"}],"@typescript-eslint/naming-convention":["error",{"format":null,"selector":"default"},{"format":null,"prefix":[],"selector":"interface"}],"@typescript-eslint/no-parameter-properties":"off","@typescript-eslint/explicit-member-accessibility":"off"},"parser":"@typescript-eslint/parser","extends":["eslint:recommended","plugin:@typescript-eslint/eslint-recommended","plugin:@typescript-eslint/recommended","prettier","plugin:prettier/recommended"],"plugins":["jest","@typescript-eslint"],"overrides":[{"files":["*.js"],"rules":{"@typescript-eslint/no-var-requires":["off"],"@typescript-eslint/explicit-function-return-type":["off"]}}],"parserOptions":{"sourceType":"module","ecmaVersion":2018}},"_hasShrinkwrap":false,"devDependencies":{"jest":"^27.4.5","husky":"^7.0.0","eslint":"^8.5.0","express":"^4.17.1","prettier":"^2.2.1","source-map":"~0.7.3","stats-lite":"^2.2.0","typescript":"^4.2.4","@babel/core":"^7.14.0","@types/jest":"^27.4.0","lint-staged":"^12.1.4","stream-json":"^1.7.1","babel-eslint":"^10.1.0","memorystream":"^0.3.1","through2-map":"^3.0.0","babel-polyfill":"^6.26.0","@babel/preset-env":"^7.14.0","sort-package-json":"^1.49.0","eslint-plugin-jest":"^25.3.3","@types/memorystream":"^0.3.0","eslint-config-prettier":"^8.3.0","eslint-plugin-prettier":"^4.0.0","@babel/preset-typescript":"^7.13.0","@typescript-eslint/parser":"^5.8.1","@typescript-eslint/eslint-plugin":"^5.8.1","@babel/plugin-transform-typescript":"^7.13.0","@babel/plugin-proposal-class-properties":"^7.13.0","@babel/plugin-proposal-optional-chaining":"^7.13.12","@babel/plugin-proposal-nullish-coalescing-operator":"^7.13.8"},"_npmOperationalInternal":{"tmp":"tmp/sitemap_8.0.2_1761715280820_0.33911836643666926","host":"s3://npm-registry-packages-npm-production"},"readme":"# sitemap ![MIT License](https://img.shields.io/npm/l/sitemap)[![Build Status](https://github.com/ekalinin/sitemap.js/workflows/Node%20CI/badge.svg)](https://github.com/ekalinin/sitemap.js/actions)![Monthly Downloads](https://img.shields.io/npm/dm/sitemap)\n\n**sitemap** is a high-level streaming sitemap-generating library/CLI that\nmakes creating [sitemap XML](http://www.sitemaps.org/) files easy. [What is a sitemap?](https://support.google.com/webmasters/answer/156184?hl=en&ref_topic=4581190)\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Generate a one time sitemap from a list of urls](#generate-a-one-time-sitemap-from-a-list-of-urls)\n- [Example of using sitemap.js with](#serve-a-sitemap-from-a-server-and-periodically-update-it) [express](https://expressjs.com/)\n- [Generating more than one sitemap](#create-sitemap-and-index-files-from-one-large-list)\n- [Options you can pass](#options-you-can-pass)\n- [Examples](#examples)\n- [API](#api)\n- [Maintainers](#maintainers)\n- [License](#license)\n\n## Installation\n\n```sh\nnpm install --save sitemap\n```\n\nRequires Node.js >= 22.22.1. This package is **ESM-only** — it no longer ships a\nCommonJS build. Load it with `import`; `require('sitemap')` works only on Node\nversions with built-in `require(esm)` support, which needs 22.12 or later;\nthe minimum is 22.22.1 to match the toolchain used to develop it.\n\n## Generate a one time sitemap from a list of urls\n\nIf 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.\n\n```sh\nnpx sitemap < listofurls.txt # `npx sitemap -h` for more examples and a list of options.\n```\n\nFor programmatic one time generation of a sitemap try:\n\n```js\nimport { SitemapStream, streamToPromise } from 'sitemap'\nimport { Readable } from 'stream'\n\n// An array with your links\nconst links = [{ url: '/page-1/',  changefreq: 'daily', priority: 0.3  }]\n\n// Create a stream to write to\nconst stream = new SitemapStream( { hostname: 'https://...' } )\n\n// Return a promise that resolves with your XML string\nreturn streamToPromise(Readable.from(links).pipe(stream)).then((data) =>\n  data.toString()\n)\n```\n\n## Serve a sitemap from a server and periodically update it\n\nUse this if you have less than 50 thousand urls. See SitemapAndIndexStream for if you have more.\n\n```js\nimport express from 'express'\nimport { SitemapStream, streamToPromise } from 'sitemap'\nimport { createGzip } from 'zlib'\nimport { Readable } from 'stream'\n\nconst app = express()\nlet sitemap\n\napp.get('/sitemap.xml', function(req, res) {\n  res.header('Content-Type', 'application/xml');\n  res.header('Content-Encoding', 'gzip');\n  // if we have a cached entry send it\n  if (sitemap) {\n    res.send(sitemap)\n    return\n  }\n\n  try {\n    const smStream = new SitemapStream({ hostname: 'https://example.com/' })\n    const pipeline = smStream.pipe(createGzip())\n\n    // pipe your entries or directly write them.\n    smStream.write({ url: '/page-1/',  changefreq: 'daily', priority: 0.3 })\n    smStream.write({ url: '/page-2/',  changefreq: 'monthly',  priority: 0.7 })\n    smStream.write({ url: '/page-3/'})    // changefreq: 'weekly',  priority: 0.5\n    smStream.write({ url: '/page-4/',   img: \"http://urlTest.com\" })\n    /* or use\n    Readable.from([{url: '/page-1'}...]).pipe(smStream)\n    if you are looking to avoid writing your own loop.\n    */\n\n    // cache the response\n    streamToPromise(pipeline).then(sm => sitemap = sm)\n    // make sure to attach a write stream such as streamToPromise before ending\n    smStream.end()\n    // stream write the response\n    pipeline.pipe(res).on('error', (e) => {throw e})\n  } catch (e) {\n    console.error(e)\n    res.status(500).end()\n  }\n})\n\napp.listen(3000, () => {\n  console.log('listening')\n});\n```\n\n## Create sitemap and index files from one large list\n\nIf 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.\n\n```js\nimport { createReadStream, createWriteStream } from 'fs'\nimport { resolve } from 'path'\nimport { createGzip } from 'zlib'\nimport { simpleSitemapAndIndex, lineSeparatedURLsToSitemapOptions } from 'sitemap'\n\n// writes sitemaps and index out to the destination you provide.\nsimpleSitemapAndIndex({\n  hostname: 'https://example.com',\n  destinationDir: './',\n  sourceData: lineSeparatedURLsToSitemapOptions(\n    createReadStream('./your-data.json.txt')\n  ),\n  // sourceData can also be:\n  // sourceData: [{ url: '/page-1/', changefreq: 'daily'}, ...],\n  // or\n  // sourceData: './your-data.json.txt',\n  limit: 45000, // optional, default: 45000\n  gzip: true, // optional, default: true\n  publicBasePath: '/sitemaps/', // optional, default: './'\n  xslUrl: 'https://example.com/sitemap.xsl', // optional XSL stylesheet\n}).then(() => {\n  // Do follow up actions\n})\n```\n\nWant to customize that?\n\n```js\nimport { createReadStream, createWriteStream } from 'fs'\nimport { resolve } from 'path'\nimport { createGzip } from 'zlib'\nimport { Readable, pipeline } from 'stream'\nimport { SitemapAndIndexStream, SitemapStream, lineSeparatedURLsToSitemapOptions } from 'sitemap'\n\nconst sms = new SitemapAndIndexStream({\n  limit: 50000, // defaults to 45000\n  lastmodDateOnly: false, // print date not time\n  // SitemapAndIndexStream will call this user provided function every time\n  // it needs to create a new sitemap file. You merely need to return a stream\n  // for it to write the sitemap urls to and the expected url where that sitemap will be hosted\n  getSitemapStream: (i) => {\n    const sitemapStream = new SitemapStream({ hostname: 'https://example.com' });\n    // if your server automatically serves sitemap.xml.gz when requesting sitemap.xml leave this line be\n    // otherwise you will need to add .gz here and remove it a couple lines below so that both the index \n    // and the actual file have a .gz extension\n    const path = `./sitemap-${i}.xml`; \n\n    const ws = createWriteStream(resolve(path + '.gz')); // write it to sitemap-NUMBER.xml\n    // Use pipeline() rather than pipe() so a gzip failure also fails ws,\n    // which SitemapAndIndexStream watches. Passing the error on to sms also\n    // reports a failure that comes after sms stopped watching ws.\n    pipeline(sitemapStream, createGzip(), ws, (err) => { // compress the output of the sitemap\n      if (err) sms.destroy(err);\n    });\n\n    return [new URL(path, 'https://example.com/subdir/').toString(), sitemapStream, ws];\n  },\n});\n\n// when reading from a file\nlineSeparatedURLsToSitemapOptions(\n  createReadStream('./your-data.json.txt')\n)\n.pipe(sms)\n.pipe(createGzip())\n.pipe(createWriteStream(resolve('./sitemap-index.xml.gz')));\n\n// or reading straight from an in-memory array\nsms\n.pipe(createGzip())\n.pipe(createWriteStream(resolve('./sitemap-index.xml.gz')));\n\nconst arrayOfSitemapItems = [{ url: '/page-1/', changefreq: 'daily'}, ...]\nReadable.from(arrayOfSitemapItems).pipe(sms)\n// or\narrayOfSitemapItems.forEach(item => sms.write(item))\nsms.end() // necessary to let it know you've got nothing else to write\n```\n\n### Options you can pass\n\n```js\nimport { SitemapStream, streamToPromise } from 'sitemap'\n\nconst smStream = new SitemapStream({\n  hostname: 'http://www.mywebsite.com',\n  xslUrl: \"https://example.com/style.xsl\",\n  lastmodDateOnly: false, // print date not time\n  xmlns: { // trim the xml namespace\n    news: true, // flip to false to omit the xml namespace for news\n    xhtml: true,\n    image: true,\n    video: true,\n    custom: [\n      'xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"',\n      'xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"',\n    ],\n  }\n })\n// coalesce stream to value\n// alternatively you can pipe to another stream\nstreamToPromise(smStream).then(console.log)\n\nsmStream.write({\n  url: '/page1',\n  changefreq: 'weekly',\n  priority: 0.8, // A hint to the crawler that it should prioritize this over items less than 0.8\n})\n\n// each sitemap entry supports many options\n// See [Sitemap Item Options](./api.md#sitemap-item-options) below for details\nsmStream.write({\n  url: 'http://test.com/page-1/',\n  img: [\n    {\n      url: 'http://test.com/img1.jpg',\n      caption: 'An image',\n      title: 'The Title of Image One',\n      geoLocation: 'London, United Kingdom',\n      license: 'https://creativecommons.org/licenses/by/4.0/'\n    },\n    {\n      url: 'http://test.com/img2.jpg',\n      caption: 'Another image',\n      title: 'The Title of Image Two',\n      geoLocation: 'London, United Kingdom',\n      license: 'https://creativecommons.org/licenses/by/4.0/'\n    }\n  ],\n  video: [\n    {\n      thumbnail_loc: 'http://test.com/tmbn1.jpg',\n      title: 'A video title',\n      description: 'This is a video'\n    },\n    {\n      thumbnail_loc: 'http://test.com/tmbn2.jpg',\n      title: 'A video with an attribute',\n      description: 'This is another video',\n      'player_loc': 'http://www.example.com/videoplayer.mp4?video=123',\n      'player_loc:autoplay': 'ap=1',\n      'player_loc:allow_embed': 'yes'\n    }\n  ],\n  links: [\n    { lang: 'en', url: 'http://test.com/page-1/' },\n    { lang: 'ja', url: 'http://test.com/page-1/ja/' }\n  ],\n  androidLink: 'android-app://com.company.test/page-1/',\n  news: {\n    publication: {\n      name: 'The Example Times',\n      language: 'en'\n    },\n    genres: 'PressRelease, Blog',\n    publication_date: '2008-12-23',\n    title: 'Companies A, B in Merger Talks',\n    keywords: 'business, merger, acquisition, A, B',\n    stock_tickers: 'NASDAQ:A, NASDAQ:B'\n  }\n})\n// indicate there is nothing left to write\nsmStream.end()\n```\n\n## Filtering sitemap entries during parsing\n\nYou can filter or delete items from a sitemap while parsing by piping through a custom Transform stream. This is useful when you want to selectively process only certain URLs from an existing sitemap.\n\n```js\nimport { createReadStream } from 'fs'\nimport { Transform } from 'stream'\nimport { XMLToSitemapItemStream } from 'sitemap'\n\n// Create a filter that only keeps certain URLs\nconst filterStream = new Transform({\n  objectMode: true,\n  transform(item, encoding, callback) {\n    // Only keep URLs containing '/blog/'\n    if (item.url.includes('/blog/')) {\n      callback(undefined, item)  // Keep this item\n    } else {\n      callback()  // Skip this item (effectively \"deleting\" it)\n    }\n  }\n})\n\n// Parse and filter\ncreateReadStream('./sitemap.xml')\n  .pipe(new XMLToSitemapItemStream())\n  .pipe(filterStream)\n  .on('data', (item) => {\n    console.log('Filtered URL:', item.url)\n  })\n```\n\nYou can also chain multiple filters together, filter based on priority/changefreq, or use the filtered results to generate a new sitemap. See [examples/filter-sitemap.js](./examples/filter-sitemap.js) for more filtering patterns.\n\n## Examples\n\nFor more examples see the [examples directory](./examples/)\n\n## API\n\nFull API docs can be found [here](./api.md)\n\n## Maintainers\n\n- [@ekalinin](https://github.com/ekalinin)\n- [@derduher](https://github.com/derduher)\n\n## License\n\nSee [LICENSE](https://github.com/ekalinin/sitemap.js/blob/master/LICENSE) file.\n","publish_time":1761715281037,"_cnpm_publish_time":1761715281037,"dist-tags":{"latest":"10.0.0","legacy":"7.1.3","v8-latest":"8.0.3"}}