Generates a sitemap index and per-collection XML sitemaps split into chunks, regenerated lazily from the database after collection hooks mark the cache dirty. Next.js route helpers and a robots.txt generator are included, and the delivery, caching and invalidation layers can be replaced for other stacks. Requires Payload 3.30 or later.
Payload plugin that generates chunked, lazily cached XML sitemaps with hook-driven invalidation and robots.txt helpers. Next.js + Vercel work out of the box; every layer is overridable for other stacks.
Installation
npm i @whatworks/payload-sitemap16
Stars
1
Forks
2
Open Issues
3 days ago
Last Updated
195
Weekly Downloads
v0.2.1
npm Version
130.8 KB
Unpacked Size
0
Dependencies
16+1 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 16 |
| Dec 4, 2026 | 16 |
| Dec 3, 2026 | 16 |
| Dec 2, 2026 | 16 |
| Dec 1, 2026 | 16 |
| Nov 30, 2026 | 16 |
| Nov 29, 2026 | 16 |
| Nov 28, 2026 | 16 |
| Nov 27, 2026 | 16 |
| Nov 26, 2026 | 16 |
| Nov 25, 2026 | 16 |
| Nov 24, 2026 | 16 |
| Nov 23, 2026 | 16 |
| Nov 22, 2026 | 16 |
| Nov 21, 2026 | 16 |
| Nov 20, 2026 | 16 |
| Nov 19, 2026 | 16 |
| Nov 18, 2026 | 16 |
| Nov 17, 2026 | 15 |
| Nov 16, 2026 | 15 |
| Nov 15, 2026 | 15 |
| Nov 14, 2026 | 15 |
| Nov 13, 2026 | 15 |
| Nov 12, 2026 | 15 |
| Nov 11, 2026 | 15 |
| Nov 10, 2026 | 15 |
| Nov 9, 2026 | 15 |
| Nov 8, 2026 | 15 |
| Nov 7, 2026 | 15 |
| Nov 6, 2026 | 15 |
| Nov 5, 2026 | 15 |
| Nov 4, 2026 | 15 |
| Nov 3, 2026 | 15 |
| Nov 2, 2026 | 15 |
| Nov 1, 2026 | 15 |
| Oct 31, 2026 | 15 |
| Oct 30, 2026 | 15 |
| Oct 29, 2026 | 15 |
| Oct 28, 2026 | 15 |
| Oct 27, 2026 | 15 |
| Oct 26, 2026 | 15 |
| Oct 25, 2026 | 15 |
| Oct 24, 2026 | 15 |
| Oct 23, 2026 | 15 |
| Oct 22, 2026 | 15 |
| Oct 21, 2026 | 15 |
| Oct 20, 2026 | 15 |
| Oct 19, 2026 | 15 |
| Oct 18, 2026 | 15 |
| Oct 17, 2026 | 15 |
| Oct 16, 2026 | 15 |
| Oct 15, 2026 | 15 |
| Oct 14, 2026 | 15 |
| Oct 13, 2026 | 15 |
| Oct 12, 2026 | 15 |
| Oct 11, 2026 | 15 |
| Oct 10, 2026 | 15 |
| Oct 9, 2026 | 15 |
| Oct 8, 2026 | 15 |
| Oct 7, 2026 | 15 |
| Oct 6, 2026 | 15 |
| Oct 5, 2026 | 15 |
| Oct 4, 2026 | 15 |
| Oct 3, 2026 | 15 |
| Oct 2, 2026 | 15 |
| Oct 1, 2026 | 15 |
| Sep 30, 2026 | 15 |
| Sep 29, 2026 | 15 |
| Sep 28, 2026 | 15 |
| Sep 27, 2026 | 15 |
| Sep 26, 2026 | 15 |
| Sep 25, 2026 | 15 |
| Sep 24, 2026 | 15 |
| Sep 23, 2026 | 15 |
| Sep 22, 2026 | 15 |
| Sep 21, 2026 | 15 |
| Sep 20, 2026 | 15 |
| Sep 19, 2026 | 15 |
| Sep 18, 2026 | 15 |
| Sep 17, 2026 | 15 |
| Sep 16, 2026 | 15 |
| Sep 15, 2026 | 15 |
| Sep 14, 2026 | 15 |
| Sep 13, 2026 | 15 |
| Sep 12, 2026 | 15 |
| Sep 11, 2026 | 15 |
| Sep 10, 2026 | 15 |
| Sep 9, 2026 | 15 |
| Sep 8, 2026 | 15 |
| Sep 7, 2026 | 15 |
| Sep 6, 2026 | 15 |
Shared by 12 plugins in what-works-global/payload-packages.
243+225 since Sep 6
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 243 |
| Dec 4, 2026 | 289 |
| Dec 3, 2026 | 257 |
| Dec 2, 2026 | 262 |
| Dec 1, 2026 | 291 |
| Nov 30, 2026 | 289 |
| Nov 29, 2026 | 245 |
| Nov 28, 2026 | 195 |
| Nov 27, 2026 | 148 |
| Nov 26, 2026 | 153 |
| Nov 25, 2026 | 168 |
| Nov 24, 2026 | 182 |
| Nov 23, 2026 | 183 |
| Nov 22, 2026 | 213 |
| Nov 21, 2026 | 217 |
| Nov 20, 2026 | 303 |
| Nov 19, 2026 | 265 |
| Nov 18, 2026 | 329 |
| Nov 17, 2026 | 288 |
| Nov 16, 2026 | 298 |
| Nov 15, 2026 | 305 |
| Nov 14, 2026 | 334 |
| Nov 13, 2026 | 284 |
| Nov 12, 2026 | 284 |
| Nov 11, 2026 | 233 |
| Nov 10, 2026 | 262 |
| Nov 9, 2026 | 254 |
| Nov 8, 2026 | 220 |
| Nov 7, 2026 | 186 |
| Nov 6, 2026 | 154 |
| Nov 5, 2026 | 133 |
| Nov 4, 2026 | 108 |
| Nov 3, 2026 | 77 |
| Nov 2, 2026 | 76 |
| Nov 1, 2026 | 71 |
| Oct 31, 2026 | 64 |
| Oct 30, 2026 | 61 |
| Oct 29, 2026 | 53 |
| Oct 28, 2026 | 13 |
| Oct 27, 2026 | 18 |
| Oct 26, 2026 | 18 |
| Oct 25, 2026 | 26 |
| Oct 24, 2026 | 27 |
| Oct 23, 2026 | 18 |
| Oct 22, 2026 | 26 |
| Oct 21, 2026 | 33 |
| Oct 20, 2026 | 28 |
| Oct 19, 2026 | 26 |
| Oct 18, 2026 | 30 |
| Oct 17, 2026 | 64 |
| Oct 16, 2026 | 65 |
| Oct 15, 2026 | 61 |
| Oct 14, 2026 | 64 |
| Oct 13, 2026 | 67 |
| Oct 12, 2026 | 68 |
| Oct 11, 2026 | 81 |
| Oct 10, 2026 | 52 |
| Oct 9, 2026 | 71 |
| Oct 8, 2026 | 68 |
| Oct 7, 2026 | 58 |
| Oct 6, 2026 | 58 |
| Oct 5, 2026 | 57 |
| Oct 4, 2026 | 33 |
| Oct 3, 2026 | 35 |
| Oct 2, 2026 | 15 |
| Oct 1, 2026 | 25 |
| Sep 30, 2026 | 28 |
| Sep 29, 2026 | 25 |
| Sep 28, 2026 | 25 |
| Sep 27, 2026 | 27 |
| Sep 26, 2026 | 21 |
| Sep 25, 2026 | 21 |
| Sep 24, 2026 | 14 |
| Sep 23, 2026 | 22 |
| Sep 22, 2026 | 26 |
| Sep 21, 2026 | 30 |
| Sep 20, 2026 | 30 |
| Sep 19, 2026 | 30 |
| Sep 18, 2026 | 32 |
| Sep 17, 2026 | 29 |
| Sep 16, 2026 | 20 |
| Sep 15, 2026 | 15 |
| Sep 14, 2026 | 12 |
| Sep 13, 2026 | 10 |
| Sep 12, 2026 | 9 |
| Sep 11, 2026 | 9 |
| Sep 10, 2026 | 13 |
| Sep 9, 2026 | 12 |
| Sep 8, 2026 | 13 |
| Sep 7, 2026 | 14 |
| Sep 6, 2026 | 18 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1064440892-sitemap)<a href="https://payloaddirectory.dev/plugins/1064440892-sitemap"><img src="https://payloaddirectory.dev/badge/1064440892-sitemap.svg" alt="Payload Directory"></a>README
Chunked, lazily cached XML sitemaps for Payload with hook-driven invalidation and robots.txt helpers.
Next.js + Vercel work with near-zero config; every layer — delivery, caching, invalidation, robots output — is overridable for other stacks (decoupled frontends, self-hosted servers, SSG builds).
plugin-nested-docs re-saving children), publishes, unpublishes, and deletes all come out correct without any change detection./sitemap.xml is a <sitemapindex> referencing pages-1.xml, posts-1.xml, … split at chunkSize (default 25,000; protocol limit 50,000).select, depth: 0, and a _status filter applied only when the collection actually has drafts enabled.'auto' (default), entries are cached in the Next.js Data Cache with tags (revalidateTag invalidation — works across serverless instances on Vercel) and fall back to an in-memory cache outside Next. Responses also carry Cache-Control: s-maxage so a CDN absorbs crawler traffic.// payload.config.ts
import { sitemapPlugin } from '@whatworks/payload-sitemap'
export default buildConfig({
plugins: [
sitemapPlugin({
collections: {
pages: {
path: ({ doc }) => (doc.slug === 'home' ? '/' : `/${doc.slug}`),
select: { slug: true },
},
},
}),
],
})
// app/sitemap.xml/route.ts
import config from '@payload-config'
import { createSitemapIndexRoute } from '@whatworks/payload-sitemap/next'
export const dynamic = 'force-dynamic'
export const { GET } = createSitemapIndexRoute({ config })
// app/sitemaps/[sitemap]/route.ts
import config from '@payload-config'
import { createSitemapChunkRoute } from '@whatworks/payload-sitemap/next'
export const dynamic = 'force-dynamic'
export const { GET } = createSitemapChunkRoute({ config })
// app/robots.ts
import config from '@payload-config'
import { createRobots } from '@whatworks/payload-sitemap/next'
export default createRobots({ config })
This is the entire setup — no env vars required. robots.txt disallows everything outside production (VERCEL_ENV/NODE_ENV), and disallows the admin + API routes in production.
siteUrl is resolvedEvery URL in the sitemap is joined onto the first available of:
siteUrl plugin option — a string, or a function ({ request }) => string with full controlx-forwarded-proto/x-forwarded-host, then Host, then the request URL's originSITE_URL → NEXT_PUBLIC_SERVER_URLhttps://$VERCEL_PROJECT_PRODUCTION_URLThe request deliberately outranks the env vars: with zero configuration, a deployment
answering on several hosts (example.com, staging.example.com, *.vercel.app) emits
each sitemap on the host it was requested from. Set the siteUrl option when multiple
public hosts must emit one canonical domain. The env vars cover request-less contexts
(build steps, background jobs); Vercel's project URL comes last because it is derived —
and frozen at build time — rather than configured. The app/robots.ts helper reads
next/headers when the origin isn't pinned by an option string, which makes that route
dynamic.
Host headers are client-controlled, so request-derived origins are never written to the
shared cache — entries are cached as site-relative paths and joined onto the resolved
origin per request. A forged Host can only distort the forger's own response, provided
your proxy/CDN sets x-forwarded-host itself (Vercel does) instead of passing a
client-supplied value through to a shared HTTP cache.
sitemapPlugin({
// Required. Per-collection config, typed against your generated types.
collections: {
pages: {
// Return a path (joined to siteUrl) or an absolute URL (used verbatim).
// Return null/undefined to omit the doc.
path: ({ doc }) => `/${doc.slug}`,
// Fields your path()/lastMod() need. id/updatedAt are always included.
select: { slug: true, breadcrumbs: true },
lastMod: 'publishedAt', // field name, (doc) => Date, or false. Default 'updatedAt'
where: {}, // extra query constraints
chunkSize: 10_000, // per-collection override
changeFreq: 'weekly', // opt-in; Google ignores it
priority: 0.5, // opt-in; Google ignores it
// Override the default invalidation heuristic (invalidate on any change
// except a draft save with no published transition):
shouldInvalidate: ({ doc, previousDoc, operation }) => true,
},
},
// String, or a function with full control (multi-tenant, per-request logic).
// Default: incoming request → env chain (see “How siteUrl is resolved”).
siteUrl: ({ request }) => `https://${request.headers.get('host')}`,
trailingSlash: false,
chunkSize: 25_000,
// Extra routes: static array, or an async function (e.g. read a global).
routes: async ({ payload }) => [{ path: '/search' }],
// Injected admin fields. Default: an `excludeFromSitemap` sidebar checkbox.
// `group` nests them inside the group field (or named tab) with that name —
// e.g. an existing `metadata` group. Dot notation reaches nested containers
// (`'seo.metadata'`); missing segments are created as groups on collections
// that lack them. The exclude flag then lives at `metadata.excludeFromSitemap`.
adminFields: { exclude: true, group: 'metadata' },
// 'auto' (default) | 'memory' | 'none' | custom { wrap, invalidate } adapter.
cache: 'auto',
// REST endpoints under the API route. DISABLED by default — the Next route
// handlers above are the primary delivery.
endpoints: {
path: '/sitemap', // → /api/sitemap/index.xml, /api/sitemap/pages-1.xml
access: ({ req }) => true, // XML access; default public once enabled
json: true, // /api/sitemap/entries.json; default access: req.user
cacheControl: 'public, max-age=0, s-maxage=600, stale-while-revalidate=86400',
origin: 'https://cms.example.com', // index chunk-URL origin; default: request origin
},
// Defaults for robots output (createRobots / generateRobotsTxt).
robots: {
allowIndexing: undefined, // default VERCEL_ENV/NODE_ENV
disallow: ['/drafts/'], // appended to the default rule
rules: undefined, // replace default rules entirely
sitemaps: undefined, // default `${siteUrl}/sitemap.xml`
transform: (robots) => robots, // final say over the computed output
},
disabled: false, // keeps injected fields for schema/migration consistency
})
Payload standalone as a headless CMS, frontend elsewhere (Astro, SvelteKit, …):
endpoints: true). The sitemap serves from
https://cms.example.com/api/sitemap/index.xml./sitemap.xml → the CMS endpoint from your frontend, or declare it
cross-host in the frontend's robots.txt (sanctioned by sitemaps.org):
Sitemap: https://cms.example.com/api/sitemap/index.xml/api/sitemap/entries.json (authenticated by default)
or call getSitemapEntries(payload) in a build script and render however you like.generateRobotsTxt(config, overrides?) returns a robots.txt string for any server.On a long-running self-hosted server, set cache: 'memory' — hooks invalidate it
in-process. For anything else, implement the two-method SitemapCache interface
(wrap, invalidate) — e.g. backed by Redis — and pass it as cache.
Export (.) | Purpose |
|---|---|
sitemapPlugin(config) | The Payload plugin |
getSitemapEntries(payload, opts?) | All cached entries keyed by group |
invalidateSitemap(payload, groups?) | Manual invalidation (e.g. from a global's hook that feeds routes) |
generateRobotsTxt(config, overrides?) | robots.txt string for any delivery |
getIndexItems / getChunkEntries / buildUrlsetXml / buildSitemapIndexXml | Building blocks for custom delivery |
SITEMAP_CACHE_TAG / sitemapCacheTag(group) | Next cache tags, for custom revalidateTag calls |
Export (./next) | Purpose |
|---|---|
createSitemapIndexRoute({ config, chunksPath?, cacheControl? }) | GET handler for app/sitemap.xml/route.ts |
createSitemapChunkRoute({ config, param?, cacheControl? }) | GET handler for app/sitemaps/[sitemap]/route.ts |
createRobots({ config, ...robotsOverrides }) | Default export for app/robots.ts |
pnpm dev (from packages/sitemap) boots the sandbox in dev/ — a Next app with the
admin at /admin (login form comes prefilled) and a demo
page at / listing every delivery surface plus the live cached
entries. It seeds a drafts-enabled pages collection, a draftless legal collection,
a draft-only doc and an excludeFromSitemap doc into a throwaway SQLite database
(dev/.dbs/, gitignored — delete it to reseed). Publish/delete docs in the admin and
reload to watch hook-driven invalidation land.
changefreq/priority are opt-in because Google ignores both; lastmod is the
only freshness signal it uses. Skipping them keeps the admin sidebar and XML lean.after() (post-response,
post-commit; uses waitUntil on Vercel) with a plain macrotask fallback outside Next.
revalidateTag is called with { expire: 0 } for instant expiry on Next 16; Next 15
ignores the extra argument.s-maxage=600 means a CDN may serve a
sitemap up to 10 minutes stale after a publish — regeneration is cheap behind it, so
tune cacheControl if you need tighter freshness._status filter applies exactly when the collection
has drafts enabled, so collections without drafts also work (no _status query error).payload sitemap plugin
Generate an XML sitemap from Payload collections with optional caching and a regenerate endpoint
44186/wk46v3
seo
SEO fields, settings global and automatic redirects for Payload, with Next.js metadata, sitemap and robots helpers
75303/wk3v3
payload seo analyzer
Offline on-page SEO analysis, admin dashboard, sitemaps and JSON-LD for Payload 3 and Next.js sites
72880/wk17v3
payload plugin structured data
JSON-LD structured data for Payload pages, editable from admin settings and per-document overrides
6943/wk1v3
payload plugin seo jsonld
JSON-LD builders for Payload v3 shops: Product, BreadcrumbList, ItemList, WebSite and Organization
617/wk1v3
advanced seo plugin
SEO meta group, global defaults, hreflang alternates, OG image generation and JSON-LD builders for Payload collections
09/wk3v3