sitemap.xml

Version 0.0.1 · Owners: @benallfree

Walkthrough for app owners: sitemap.xml. This page is the technical reference.

Search engines read /sitemap.xml to find a site's pages. This extension answers it when your app has no sitemap.xml of its own, from every source that knows a URL:

  • Pages. Every page in pb_pages, and what a [param] route's sitemap export lists (see Pages).
  • pb_public. Every .html file (index.html as its folder, /docs/), skipping names starting with . or _ and 404.html.
  • Settings. Extra URLs you list.
  • Extensions and pb_hooks. $sitemapXml.add(...) and sitemapxmlv1.Add.

Private paths (robots.txt) are left out of all of them, duplicates are dropped, and when the app isn't indexable (dev mode, or Keep this app out of search results) the sitemap is empty. An empty sitemap answers 404 and robots.txt doesn't point at it.

  • Your own file always wins. Put sitemap.xml in pb_public or pb_pages (or serve the path from a route) and that answers instead, whole.
  • Big sites. Past 50,000 URLs /sitemap.xml becomes a sitemap index over /sitemap-1.xml, /sitemap-2.xml, ...

It provides the sitemapxml/v1 contract.

Install · Configure · Use · Integrations · Example

Install

It's built into pocketone and on in every app: a member of the standard set, so a Go build made with standard.New() has it too. On its own:

extkit.Setup(app, []extkit.Extension{sitemapxml.New(sitemapxml.Config{})}, nil, nil)

Config.PublicDir is the static files folder it lists (default: pb_public next to pb_data). The module is pocketone.dev/ext/sitemap-xml.

Configure

Settings → Extensions → sitemap.xml:

Field What it does
Leave out pb_public's HTML files Lists no pb_public file.
Extra URLs One per line: a path on this app (/pricing) or a full URL.

They're kept in the key-value store as _sitemap-xml/settings, so they ride along in backups. Pages, private paths and noindex are set where they live: in pb_pages and in Settings → Extensions → robots.txt.

To turn the extension off on a single app, in pocketone.yaml:

sitemap-xml:
  enabled: false

On a multisite host that doesn't reach the instances: an instance sets extensions.sitemap-xml.enabled: false.

Use

Open https://<your app>/sitemap.xml:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url><loc>https://notes.example.com/</loc></url>
  <url><loc>https://notes.example.com/about</loc><lastmod>2026-11-30</lastmod></url>
</urlset>

Add URLs from pb_hooks

// pb_hooks/sitemap.pb.js
$sitemapXml.add("/pricing")
$sitemapXml.add(["/about", { path: "/changelog", lastmod: "2026-12-01" }])

// run each time the sitemap is built: query anything
$sitemapXml.add((req) => {
  const posts = $app.findRecordsByFilter("posts", "published = true", "-updated", 0, 0)
  return posts.map((p) => ({ path: `/blog/${p.get("slug")}`, lastmod: p.get("updated") }))
})

An entry is a path, a full URL, or { path, lastmod }. A function gets { origin } and may be async; one that throws is left out and logged, and the rest of the sitemap still answers. A hooks reload starts over with what your files add again.

The URL list is reused for a minute, since sources may query the database or run page code. The file is served as application/xml with a five-minute Cache-Control, for GET and HEAD only.

Commands and APIs

Generated from the pocketone binary and the contracts this extension provides.

JavaScript API

What it adds to pb_hooks and page code: sitemap.xml JavaScript API.

Integrations

Works with

Extension How they fit
robots.txt Private paths are left out; the sitemap is empty when the app isn't indexable; robots.txt points at the sitemap when there's one to read.
Pages Lists every page; sitemap: false (front matter or a .ts export) leaves one out; a [param] route's sitemap function lists its URLs. A pb_pages/sitemap.xml answers instead of the generated file.
Settings Shows the form (settings/v1).
Key-Value Store Keeps the settings (kv/v1, the private name _sitemap-xml/settings).
Multisite Every instance answers its own /sitemap.xml with its own pages and URLs.

Add URLs from Go

sitemapxmlv1.Add(app, sitemapxmlv1.Source{Name: Name, Entries: func(e *core.RequestEvent) ([]sitemapxmlv1.Entry, error) {
	return []sitemapxmlv1.Entry{{Path: "/pricing"}}, nil
}})

Declare WorksWith: extkit.IDs("sitemapxml/v1").

Replace it

Another extension can provide sitemapxml/v1 and serve the file its own way from sitemapxmlv1.Sources(app). This one then steps aside.

Example

The example app answers /sitemap.xml with its pb_public HTML files and two URLs it adds itself.

// Command example is a PocketBase app with a generated /sitemap.xml: pb_public's HTML files plus URLs the app adds
// itself. Run `go run . serve` and open http://127.0.0.1:8090/sitemap.xml.
package main

import (
	"log"

	"ganigeorgiev.com/pocketbase/pocketbase"
	"ganigeorgiev.com/pocketbase/pocketbase/core"

	sitemapxmlv1 "pocketone.dev/ext/contracts/sitemapxml/v1"
	"pocketone.dev/ext/extkit"
	sitemapxml "pocketone.dev/ext/sitemap-xml"
)

func main() {
	app := pocketbase.New()
	if _, err := extkit.Setup(app, []extkit.Extension{sitemapxml.New(sitemapxml.Config{})}, nil, nil); err != nil {
		log.Fatal(err)
	}
	sitemapxmlv1.Add(app, sitemapxmlv1.Source{Name: "example", Entries: func(*core.RequestEvent) ([]sitemapxmlv1.Entry, error) {
		return []sitemapxmlv1.Entry{{Path: "/"}, {Path: "/pricing"}}, nil
	}})
	if err := app.Start(); err != nil {
		log.Fatal(err)
	}
}

Root path

/sitemap.xml (and its parts, /sitemap-N.xml) sit at the root by convention, beside /robots.txt and /llms.txt. Like them, an app replaces them with files of its own: the extension answers only what the app left as a 404.

License

MIT