@webstandard/sitemap
v2.0.1
Published
A standards-compliant generator for producing sitemap.xml files
Downloads
110
Maintainers
Readme
@webstandard/sitemap
Silent, precise, effective. No ghost routes. No false intel. Every URL accounted for.
Canonical URL:
https://alexstevovich.com/a/webstandard-sitemap-nodejs
Software URL:
https://midnightcitylights.com/software/webstandard-sitemap-nodejs
@webstandard/sitemap is a minimal, standards-compliant generator for producing sitemap.xml files in Node.js.
It provides clean classes for defining URLs, modification dates, and sitemap indexes — then outputs canonical XML exactly as search engines expect.
Installation
npm install @webstandard/sitemapExample
import { SitemapXml, SitemapXmlUrl } from '@webstandard/sitemap';
// Create a sitemap instance
const sitemap = new SitemapXml();
// Add URLs
sitemap.addUrl(
new SitemapXmlUrl('/', {
priority: 1.0,
changefreq: 'daily',
lastmod: new Date('2024-02-20'),
}),
);
sitemap.addUrl(
new SitemapXmlUrl('/about', {
priority: 0.8,
changefreq: 'weekly',
lastmod: new Date('2024-02-18'),
}),
);
// Generate XML
const xml = sitemap.output({
domain: 'https://example.com',
dateFormat: 'date-only',
});
console.log(xml);Working with Sitemap Indexes
import { SitemapXmlIndex, SitemapXmlIndexItem } from '@webstandard/sitemap';
const index = new SitemapXmlIndex();
index.addItem(
new SitemapXmlIndexItem('/sitemap1.xml', {
lastmod: new Date('2024-02-20'),
}),
);
index.addItem(
new SitemapXmlIndexItem('/sitemap2.xml', {
lastmod: new Date('2024-02-18'),
}),
);
const xml = index.output({
domain: 'https://example.com',
dateFormat: 'date-only',
});
console.log(xml);JSON Serialization
Both SitemapXml and SitemapXmlIndex support full JSON serialization and rebuilding:
const json = sitemap.toJSON();
const restored = SitemapXml.fromJSON(json);Need robots.txt?
I provide a package for robots.txt as well.
https://alexstevovich.com/a/webstandard-robots-nodejs
Ready to join the most elite Sitemap?
This package is also mirrored here: SitemapTeam6
License
Licensed under the Apache License 2.0.
