ainsleyclark

payload sitemap plugin

by ainsleyclark
SEO & metadata
v3
^3.28.1
MIT

Overview

Summary generated from the README

Builds an XML sitemap automatically from selected Payload collections. It adds per-document exclude and priority fields, supports custom routes and URL generation, and serves the sitemap through a plugin endpoint. Optional caching stores the generated result in a sitemap global. Requires Payload 3.28.1 or later and a configured hostname.

Features

  • Generates an XML sitemap from chosen collections
  • Adds excludeFromSitemap and sitemapPriority fields to each collection
  • Optional cache stored in a sitemap global with configurable duration
  • POST endpoint to regenerate the sitemap on demand
  • Custom routes, change frequency, priority and last-modified field options
  • Custom URL generation and field overrides for collections and the global

Use cases

  • Expose a search-engine sitemap for pages and posts managed in Payload
  • Exclude specific documents from the sitemap or set their priority from the admin
  • Reduce repeated generation cost on large sites by caching the sitemap

From the author

Payload Sitemap Plugin

Installation

npm i payload-sitemap-plugin

46

Stars

3

Forks

4

Open Issues

1 years ago

Last Updated

159

Weekly Downloads

v0.0.6

npm Version

61.1 KB

Unpacked Size

1

Dependencies

GitHub stars

46+1 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 202646
Dec 5, 202646
Dec 4, 202646
Dec 3, 202646
Dec 2, 202646
Dec 1, 202646
Nov 30, 202646
Nov 29, 202646
Nov 28, 202646
Nov 27, 202646
Nov 26, 202646
Nov 25, 202646
Nov 24, 202647
Nov 23, 202647
Nov 22, 202647
Nov 21, 202647
Nov 20, 202647
Nov 19, 202647
Nov 18, 202647
Nov 17, 202647
Nov 16, 202647
Nov 15, 202647
Nov 14, 202647
Nov 13, 202647
Nov 12, 202647
Nov 11, 202647
Nov 10, 202647
Nov 9, 202647
Nov 8, 202647
Nov 7, 202647
Nov 6, 202647
Nov 5, 202647
Nov 4, 202647
Nov 3, 202647
Nov 2, 202647
Nov 1, 202647
Oct 31, 202647
Oct 30, 202647
Oct 29, 202647
Oct 28, 202647
Oct 27, 202647
Oct 26, 202647
Oct 25, 202647
Oct 24, 202647
Oct 23, 202647
Oct 22, 202647
Oct 21, 202646
Oct 20, 202646
Oct 19, 202646
Oct 18, 202646
Oct 17, 202646
Oct 16, 202646
Oct 15, 202646
Oct 14, 202646
Oct 13, 202646
Oct 12, 202646
Oct 11, 202646
Oct 10, 202646
Oct 9, 202646
Oct 8, 202646
Oct 7, 202646
Oct 6, 202646
Oct 5, 202646
Oct 4, 202646
Oct 3, 202646
Oct 2, 202646
Oct 1, 202646
Sep 30, 202646
Sep 29, 202646
Sep 28, 202646
Sep 27, 202646
Sep 26, 202646
Sep 25, 202646
Sep 24, 202646
Sep 23, 202646
Sep 22, 202646
Sep 21, 202646
Sep 20, 202646
Sep 19, 202646
Sep 18, 202646
Sep 17, 202646
Sep 16, 202646
Sep 15, 202645
Sep 14, 202645
Sep 13, 202645
Sep 12, 202645
Sep 11, 202645
Sep 10, 202645
Sep 9, 202645
Sep 8, 202645
Sep 7, 202645
npm weekly downloads

159+19 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 2026159
Dec 5, 2026130
Dec 4, 2026147
Dec 3, 2026128
Dec 2, 2026109
Dec 1, 2026111
Nov 30, 2026147
Nov 29, 2026157
Nov 28, 2026175
Nov 27, 2026196
Nov 26, 2026150
Nov 25, 2026153
Nov 24, 2026167
Nov 23, 2026181
Nov 22, 2026174
Nov 21, 2026166
Nov 20, 2026266
Nov 19, 2026287
Nov 18, 2026315
Nov 17, 2026317
Nov 16, 2026267
Nov 15, 2026308
Nov 14, 2026312
Nov 13, 2026183
Nov 12, 2026175
Nov 11, 2026156
Nov 10, 2026179
Nov 9, 2026185
Nov 8, 2026193
Nov 7, 2026276
Nov 6, 2026423
Nov 5, 2026436
Nov 4, 2026495
Nov 3, 2026441
Nov 2, 2026436
Nov 1, 2026390
Oct 31, 2026298
Oct 30, 2026136
Oct 29, 2026101
Oct 28, 202628
Oct 27, 202629
Oct 26, 202628
Oct 25, 202624
Oct 24, 202621
Oct 23, 202616
Oct 22, 202623
Oct 21, 202636
Oct 20, 202637
Oct 19, 202636
Oct 18, 202634
Oct 17, 202644
Oct 16, 202650
Oct 15, 202665
Oct 14, 202676
Oct 13, 202694
Oct 12, 2026127
Oct 11, 2026130
Oct 10, 2026182
Oct 9, 2026232
Oct 8, 2026251
Oct 7, 2026257
Oct 6, 2026238
Oct 5, 2026206
Oct 4, 2026203
Oct 3, 2026145
Oct 2, 2026107
Oct 1, 202688
Sep 30, 202682
Sep 29, 202688
Sep 28, 202686
Sep 27, 202687
Sep 26, 202683
Sep 25, 202680
Sep 24, 202676
Sep 23, 2026123
Sep 22, 2026127
Sep 21, 2026128
Sep 20, 2026131
Sep 19, 2026163
Sep 18, 2026164
Sep 17, 2026178
Sep 16, 2026137
Sep 15, 2026128
Sep 14, 2026142
Sep 13, 2026139
Sep 12, 2026125
Sep 11, 2026117
Sep 10, 2026118
Sep 9, 2026126
Sep 8, 2026148
Sep 7, 2026140

Each point is npm's rolling 7-day download count.

Health Score

44/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/948059612-root.svg)](https://payloaddirectory.dev/plugins/948059612-root)
HTML
<a href="https://payloaddirectory.dev/plugins/948059612-root"><img src="https://payloaddirectory.dev/badge/948059612-root.svg" alt="Payload Directory"></a>
Updated Sep 26, 2025Created Mar 13, 2025Published Sep 26, 2025

README

Payload Sitemap Plugin

GoLang client library & SDK for Payload CMS

License: MIT Payload CMS Version npm version Test Lint ainsley.dev Twitter Handle

Introduction

This plugin provides an automatic way of syncing your Payload collections into a generated Sitemap.

  • ✅ Generates XML Sitemaps directly from your Payload collections.
  • ✅ Configurable cache system and endpoint to regenerate the sitemap.
  • ✅ Extensible with fields and config.
  • ✅ Add custom routes to your sitemap.

Installation

pnpm i payload-sitemap-plugin 

Quick Start

import { sitemapPlugin } from 'payload-sitemap-plugin';

export default buildConfig({
	plugins: [
		sitemapPlugin({
			hostname: 'https://example.com',
			cache: true,
			defaultPriority: 0.5,
			includeDrafts: true,
			includeHomepage: true,
			collections: {
				posts: {
					priority: 0.8,
					changeFreq: 'weekly',
					includeDrafts: false,
					fieldOverrides: ({ defaultFields }) => [
						...defaultFields,
						{
							name: 'customSEO',
							type: 'text',
							label: 'Custom SEO Field',
						},
					],
				},
				pages: true
			},
			generateURL: ({ doc }) => `/${doc.slug}`,
			customRoutes: [
				{
					loc: '/about',
					priority: 0.7,
					lastMod: new Date('2024-01-01')
				}
			],
			globalOverrides: {
				fields: ({ defaultFields }) => [
					...defaultFields,
					{
						name: 'extraSetting',
						type: 'text',
						label: 'Extra Setting',
					},
				],
			},
		})
	]
});

Robots.txt

To make sure search engines are able to find the sitemap XML create a robots.txt file in the front-end of your website and add the following line:

Sitemap: https://your-payload-domain.com/api/plugin-sitemap/sitemap/index.xml

Read more about the robots.txt file here.

Fields

Two fields are added to the collections that are specified enabling easy customisation of each document in the sitemap.

  • excludeFromSitemap - A checkbox field to specify whether a document should be excluded from the sitemap.
  • sitemapPriority - A select field to define the priority of a document in the sitemap, with values ranging from 0 to 1.

Caching

If caching is enabled, a sitemap global is used to store the results of sitemap generation once it has been created. This global contains a JSON representation of the sitemap, and when it was last modified.

The user is responsible for re-generating sitemaps. Refer to the regenerate endpoint below for instructions on how to manually trigger sitemap regeneration.

Visit the documentation for more details.

Endpoints

EndpointDescriptionMethod
/api/plugin-sitemap/sitemap/index.xmlThe generated sitemap XML file.GET
/api/plugin-sitemap/regenerateEndpoint to regenerate the sitemap.POST

Config

OptionDefaultDescription
hostnameRequiredBase URL for absolute links. This is required for generating fully qualified URLs in the sitemap.
cachefalseCache configuration for the sitemap. Can be a boolean (enable/disable) or an object with duration and enabled flags.
cache.duration86400 (1 day)Cache duration in seconds for storing the generated sitemap.
cache.enabledfalseIf true, caching of the generated sitemap will be enabled.
collections{}Collection-specific configuration for the sitemap. Each key corresponds to a collection slug, and custom options can be provided for that collection.
collections.[key]-Settings for a specific collection in the sitemap. If set to true, it includes all documents in that collection with default settings.
collections.[key].changeFreq-Frequency at which pages in this collection are expected to change. Can be overridden for each document.
collections.[key].includeDraftsfalseIf true, drafts for this collection will be included in the sitemap.
collections.[key].lastModField-Custom field to determine the last modified date (lastmod) for documents in the collection.
collections.[key].priority-Default priority for documents in this collection. Can be between 0.0 and 1.0.
collections.[key].fieldOverrides-Function to override or extend the default fields (sitemapPriority and excludeFromSitemap) for this collection. Returns a new array of fields.
customRoutes-Custom routes to include in the sitemap with their own configuration (change frequency, last modified date, priority).
defaultPriority0.5Default priority for all documents in the sitemap. Values range from 0.0 (lowest) to 1.0 (highest).
disabledfalseIf set to true, disables the sitemap plugin.
generateURL-Custom function to generate URLs for documents in this collection.
includeDraftsfalseIf true, includes drafts in the sitemap. This is overridden by individual collection settings.
includeHomepagetrueIf true, includes a default / entry in the sitemap.
globalOverridestrueFunction to override or extend fields on the sitemap global used for caching. Returns a new array of fields.

TODO

  • Add localisation, ability to specify alternate pages: <xhtml:link rel="alternate">
  • Allow limit and sitemaps greater than 45,000.

Contributing

Contributions are welcome! If you find any bugs or have suggestions for improvement, please open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Trademark

ainsley.dev and the ainsley.dev logo are either registered trademarks or trademarks of ainsley.dev LTD in the United Kingdom and/or other countries. All other trademarks are the property of their respective owners.

Similar plugins