{"library":"sitemap","title":"Sitemap Generator","description":"The `sitemap` package is a high-level, streaming library and CLI tool designed for generating and managing XML sitemap files according to the sitemap.org protocol. It facilitates the creation of sitemaps and sitemap indexes, supporting various content types like images, videos, and multilingual alternatives. The package is actively maintained, with version 9.0.1 being the current stable release, frequently issuing security patches across major versions (e.g., 7.x, 8.x, 9.x) and introducing significant breaking changes in major releases like v9.0.0. Key differentiators include its robust, security-focused architecture (addressing XML injection, memory DoS, and arbitrary file writes), stream-based processing for efficiency with large datasets, and a command-line interface for quick generation and validation. It offers comprehensive TypeScript support for type safety and IntelliSense.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install sitemap"],"cli":{"name":"sitemap","version":null}},"imports":["import { SitemapStream } from 'sitemap'","import { SitemapItem } from 'sitemap'","import { SitemapStream, streamToPromise } from 'sitemap'","import { simpleSitemapAndIndex } from 'sitemap'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { SitemapStream, streamToPromise, SitemapItem } from 'sitemap';\nimport { createGzip } from 'node:zlib';\nimport { Readable } from 'node:stream';\nimport { writeFile } from 'node:fs/promises';\n\nconst hostname = process.env.SITE_HOSTNAME ?? 'https://example.com';\nconst links: SitemapItem[] = [\n  { url: '/', changefreq: 'daily', priority: 1.0 },\n  { url: '/about', changefreq: 'monthly', priority: 0.7 },\n  { url: '/contact', changefreq: 'weekly', priority: 0.5, lastmod: new Date() },\n  {\n    url: '/products/widget',\n    lastmod: '2023-11-20',\n    img: [\n      { url: `${hostname}/img/widget.jpg`, caption: 'Awesome Widget' },\n    ],\n  },\n  { url: '/blog/post-1', changefreq: 'weekly' },\n  { url: '/blog/post-2', lastmod: '2024-01-15', priority: 0.8 },\n];\n\n(async () => {\n  try {\n    const sitemapStream = new SitemapStream({ hostname });\n    const pipeline = Readable.from(links).pipe(sitemapStream).pipe(createGzip());\n    const sitemapXml = await streamToPromise(pipeline);\n\n    await writeFile('./public/sitemap.xml.gz', sitemapXml);\n    console.log('Sitemap generated successfully to public/sitemap.xml.gz');\n  } catch (error) {\n    console.error('Error generating sitemap:', error);\n  }\n})();","lang":"typescript","description":"This quickstart demonstrates how to programmatically generate a gzipped sitemap XML file from a list of `SitemapItem` objects using streams, handling common URL properties and image entries.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}