Skip to content

Sitemap and robots.txt

Warlock discovers page routes and publishes sitemap artifacts through @warlock.js/web/sitemap. Configure it under web.sitemap; the standalone @warlock.js/sitemap package only builds XML.

src/config/web.ts
import type { WebConfigurations } from "@warlock.js/web";
const web: WebConfigurations = {
sitemap: {
enabled: true,
path: "/sitemap.xml",
storage: { disk: "assets", directory: "sitemaps" },
coordination: "shared",
regenerateEvery: "1d",
cacheControl: "public, max-age=300",
gzip: true,
},
robots: {
enabled: true,
groups: [{ userAgent: "*", disallow: ["/admin"] }],
},
};
export default web;

Set app.publicUrl to the canonical absolute origin before enabling a sitemap. Warlock never derives sitemap URLs from an incoming request host.

storage.directory is a dedicated relative prefix and defaults to sitemap. Omit storage.disk to use the app’s default storage. The legacy outputDir continues to support a local directory, but cannot be combined with storage.

Each successful pass writes immutable artifacts and a manifest. The main route serves the latest valid manifest; it does not generate XML for a request. Until the first successful pass, /sitemap.xml returns 503 with Retry-After: 30. A failed refresh keeps the last good manifest available.

coordination defaults to "local". Use "shared" only when selected storage provides atomic create-if-absent and consistent reads/listings. Warlock does not require Redis for sitemap coordination. Other instances discover a newer manifest at most every manifestPollMs milliseconds (default 30_000).

regenerateEvery accepts a positive millisecond value or duration such as "30s", "6h", or "1d". It is a safety refresh; changefreq is crawler metadata, not a scheduler.

Declare page sitemap policy in config.sitemap in the matching .setup.ts file.

Sitemap discovery imports page modules in Node, not in the browser. Stylesheet imports (.css, .scss, .sass, .less, .styl) in a page or in the components it imports resolve to an empty module there, so components can keep their own styles.

Static pages are included unless a page or layout sets config.sitemap: false. Dynamic routes need concrete entries:

src/web/products/[slug].setup.ts
import type { PageConfig } from "@warlock.js/web";
import { Product } from "@/app/products/product.model";
import { listPublishedSitemapProducts } from "@/app/products/list-published-sitemap-products";
export const config: PageConfig = {
sitemap: {
entries: async function productEntries() {
const products = await listPublishedSitemapProducts();
return products.map((product) => ({
path: "/products/" + encodeURIComponent(product.slug),
lastmod: product.updatedAt,
images: [{ loc: product.imageUrl }],
}));
},
invalidateOn: [Product],
},
};

Keep models and data queries in server-only modules: sitemap policy is removed from the browser projection. invalidateOn subscribes to listed Cascade models after their transaction commits, then requests a debounced refresh. Raw SQL, bulk writers, and external systems do not emit those events; call regenerateSitemap() after their work commits.

import { regenerateSitemap } from "@warlock.js/web/sitemap";
await regenerateSitemap();

Suppliers run up to four at a time; their URLs still appear in page order. A supplier receives one argument, { site, tenantKey, shared }: empty for a single-site app, the site key in multi-site mode, and for a dynamic (tenant) site the tenant’s key from web.resolveHost. A tenant site’s supplier must filter by tenantKey; see Multiple sites.

Paths are percent-encoded as the sitemap protocol requires: spaces, non-ASCII text and control characters in a path become %XX escapes, so a slug with an unusual character can never make the file invalid XML. A path you already encoded (encodeURIComponent(slug)) is left as it is.

A small sitemap is served at path. Larger or locale-split outputs publish an index with shards at /sitemaps/<generationId>/<file>. Generation URLs are immutable and may be cached for a year. The main endpoint uses sitemap.cacheControl, defaulting to public, max-age=300.

Both routes send ETag and Last-Modified. If-None-Match takes precedence over If-Modified-Since and compares weakly (W/"…" matches the strong tag); a matching GET or HEAD returns 304 without reading stored XML. If-Match compares strongly, so only the exact strong tag passes; otherwise the route answers 412. Gzipped artifacts stream with Content-Encoding: gzip.

sitemap.gzip defaults to false: the stored files stay plain XML. When http.compression is on, the response layer already compresses a served sitemap for clients that accept it, so gzip: true only changes what is stored (and the size of the stored files).

An entry can include up to 1,000 absolute HTTP(S) image URLs. Warlock emits the Google image sitemap extension only where needed. More images are dropped with a route diagnostic; use structured data or a product feed for product price, stock, and description.

web.robots.enabled registers /robots.txt. referenceSitemap defaults to true and adds the configured sitemap URL when an origin is available. A hand-written public/robots.txt takes precedence.

In a multi-site app each site can have its own policy. Set robots on a site in web.sites (or on the result of resolveHost for a tenant host); it is merged over web.robots key by key, and groups and extra are replaced whole:

src/config/web.ts
const web: WebConfigurations = {
sites: {
landing: { hosts: ["estates.app"] },
admin: {
hosts: ["admin.estates.app"],
robots: { groups: [{ userAgent: "*", disallow: ["/admin"] }] },
},
internal: { hosts: ["internal.estates.app"], robots: { enabled: false } },
},
robots: { enabled: true, groups: [{ userAgent: "*", allow: ["/"] }] },
};

A site without robots gets the global policy. A site whose merged policy has enabled: false answers 404 for /robots.txt. A site may enable robots while the global policy is off: set robots: { enabled: true, ... } on it. A dynamic site that is not indexable still answers Disallow: /.

generateSitemap() remains the low-level one-shot artifact writer. It does not publish a managed manifest or change HTTP serving state; use regenerateSitemap() for a running application.