Skip to content

Sitemap

@warlock.js/sitemap builds sitemaps.org documents. You add entries and it returns a valid XML document. It has zero runtime dependencies and knows nothing about Warlock. It has no connector, no config module, no lifecycle, and no page registry. It only generates sitemaps; it cannot parse one.

import { Sitemap } from "@warlock.js/sitemap";
const sitemap = new Sitemap({ baseUrl: "https://example.com", changefreq: "weekly" });
sitemap.add({ path: "/" });
sitemap.add({ path: "/posts/hello-world", lastmod: new Date(), priority: 0.8 });
await sitemap.saveTo("public/sitemap.xml");

Those lines work the same way in an Express handler, a cron script, a node build-sitemap.mjs, or a Warlock controller.

Two classes, split at the protocol ceiling

Section titled “Two classes, split at the protocol ceiling”

The protocol limits one file to 50,000 URLs or 50MB uncompressed.

  • Sitemap keeps every entry in memory. That makes entries(), the diagnostics, and a repeatable toXML() possible. Use it for any site under the ceiling. → Build a sitemap
  • SitemapIndex streams from source factories. It writes size-capped shards and a master index, then publishes the whole set atomically. It keeps only the current shard in memory. → Large sites

You don’t call either class yourself. @warlock.js/web finds your pages, expands locales, chooses Sitemap or SitemapIndex, generates the file at warlock build and at boot, and serves /sitemap.xml and /robots.txt. You configure all of it under web.sitemap in src/config/web.ts:

Terminal window
warlock add sitemap

→ In a Warlock app and the full Sitemap and robots.txt guide.