sitemapxmlv1
import sitemapxmlv1 "pocketone.dev/ext/contracts/sitemapxml/v1"
Package sitemapxmlv1 is the sitemapxml/v1 contract: the app's /sitemap.xml (sitemaps.org), the list of pages the app wants search engines to find. Extensions and the app's own pb_hooks add sources with Add; the provider builds the file from every source, leaves out private paths (robotstxt/v1), and serves it when the app has no sitemap.xml of its own.
Source: ext/contracts/sitemapxml/v1.
Constants
const Path = "/sitemap.xml"
Path is where the file is served.
Variables
var Contract = extkit.NewContract[Builder]("sitemapxml/v1", extkit.One)
Contract is sitemapxml/v1.
Functions
Add
func Add(app core.App, s Source)
Add adds a source to app's sitemap. Call it any time (in Register, from pb_hooks), whoever provides the contract.
Types
Builder
type Builder interface {
// Entries are the sitemap's URLs for the request, deduplicated, private paths left out.
Entries(e *core.RequestEvent) ([]Entry, error)
// Listed reports whether robots.txt should point crawlers at /sitemap.xml: it has entries, or the app serves its
// own sitemap.xml.
Listed(e *core.RequestEvent) bool
}
Builder builds the app's sitemap.
Entry
type Entry struct {
// Path is a path on this app ("/blog/hello"); Loc, an absolute URL, is used instead when set.
Path string
Loc string
// LastMod is when the page last changed in a way that matters, if the source knows (zero: left out).
LastMod time.Time
}
Entry is one URL.
Source
type Source struct {
// Name names the source (an extension, "pb_hooks", "settings"), for logs.
Name string
Entries func(e *core.RequestEvent) ([]Entry, error)
}
Source lists URLs. Entries runs whenever the sitemap is built (cached briefly by the provider); an error leaves the source out and is logged, and the rest of the sitemap still answers.
Sources
func Sources(app core.App) []Source
Sources are the sources, in the order added (for providers).
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.