make-sitemap
v1.0.1
Published
📑 Minimalist sitemap generator
Readme
make-sitemap
📑 Minimalist sitemap generator
Installation
pnpm install make-sitemapInstead of pnpm, you can also use npm, yarn or bun.
Usage
Regular sitemaps
Regular XML sitemaps can be generated using the Sitemap class:
import { Sitemap } from "make-sitemap";
const sitemap = new Sitemap();
sitemap.addUrl({
loc: "https://example.com",
lastmod: new Date(),
changefreq: "daily",
priority: 0.8,
});
const slugs = ["hello-world", "this-is-a-post", "and-another-post"];
slugs.forEach((slug) => {
sitemap.addUrl({
loc: `https://example.com/posts/${slug}`,
lastmod: new Date(),
changefreq: "weekly",
priority: 0.6,
});
});
console.log(sitemap.toXml()); // Outputs the XML string for the sitemapSitemap index
import { SitemapIndex } from "make-sitemap";
const sitemapIndex = new SitemapIndex();
sitemapIndex.addSitemap({
loc: "https://example.com/general.xml",
lastmod: new Date(),
});
sitemapIndex.addSitemap({
loc: "https://example.com/posts.xml",
lastmod: new Date(),
});
console.log(sitemapIndex.toXml()); // Outputs the XML string for the sitemap indexAdditional notes
- The
addUrlandaddSitemapmethods can accept either a single object or an array of multiple objects at once.
Types
SitemapUrl
| Property | Type | Description |
| --- | --- | --- |
| loc | string | Required. The URL of the page. |
| lastmod | string | The date when the page was last modified. This should follow the W3C Datetime format. |
| changefreq | SitemapChangefreq | How frequently the page is likely to change. |
| priority | number | The priority of this URL. This should be a value between 0.0 and 1.0. |
For more detailed information on these fields, please refer to the Sitemap Protocol.
SitemapFreq
This is a union type that can be one of the following string literals:
alwayshourlydailyweeklymonthlyyearlynever
SitemapEntry
| Property | Type | Description |
| --- | --- | --- |
| loc | string | Required. The URL of the sitemap. |
| lastmod | string | The date when the sitemap was last modified. This should follow the W3C Datetime format. |
For more detailed information on these fields, please refer to the Sitemap Protocol.
