npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

payload-sitemap-plugin

v0.0.6

Published

Payload Sitemap Plugin

Readme

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

| Endpoint | Description | Method | |-----------------------------------------|-------------------------------------|--------| | /api/plugin-sitemap/sitemap/index.xml | The generated sitemap XML file. | GET | | /api/plugin-sitemap/regenerate | Endpoint to regenerate the sitemap. | POST |

Config

| Option | Default | Description | |------------------------------------|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------| | hostname | Required | Base URL for absolute links. This is required for generating fully qualified URLs in the sitemap. | | cache | false | Cache configuration for the sitemap. Can be a boolean (enable/disable) or an object with duration and enabled flags. | | cache.duration | 86400 (1 day) | Cache duration in seconds for storing the generated sitemap. | | cache.enabled | false | If 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].includeDrafts | false | If 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). | | defaultPriority | 0.5 | Default priority for all documents in the sitemap. Values range from 0.0 (lowest) to 1.0 (highest). | | disabled | false | If set to true, disables the sitemap plugin. | | generateURL | - | Custom function to generate URLs for documents in this collection. | | includeDrafts | false | If true, includes drafts in the sitemap. This is overridden by individual collection settings. | | includeHomepage | true | If true, includes a default / entry in the sitemap. | | globalOverrides | true | Function 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.