[]previous and next page

sitemapRoute

An API route handler that serves sitemap.xml from a function of the request event.

An API route handler that serves sitemap.xml from a function of the request event.

Import#

ts
import { sitemapRoute } from "@shadow-js/dusk/server";

Signature#

ts
function sitemapRoute(
  build: (event: RequestEvent) => readonly SitemapEntry[] | Promise<readonly SitemapEntry[]>,
  options: MetadataResponseOptions & {
    readonly localize?: NonNullable<Parameters<typeof sitemapXml>[1]>["localize"];
  } = {},
): ApiHandler

Parameters#

Name Description
build Returns the entries; it may depend on the request (the host, a header).
options The response options, and localize (opt-in): rewrites the entries with the request's base and policy (localizedSitemap(i18n.routing) lists each app path once per locale with its hreflang alternates; see sitemapXml).

Returns#

A handler, for export const GET = sitemapRoute(...).

Examples#

ts
export const GET = sitemapRoute(() => [{ url: "about" }], { localize: localizedSitemap(i18n.routing) });