sitemapxml/v1
The app's /sitemap.xml: the URLs search engines should know about. The
contract owns the sources. Any extension or pb_hooks file adds one, whoever provides the contract; the provider
builds the file from them, leaves out private paths (robotstxt/v1) and serves it when
the app has no sitemap.xml of its own.
A service (sitemapxml.go).
Use
Add a source, in Register or later. It runs each time the sitemap is built:
sitemapxmlv1.Add(app, sitemapxmlv1.Source{Name: Name, Entries: func(e *core.RequestEvent) ([]sitemapxmlv1.Entry, error) {
return []sitemapxmlv1.Entry{
{Path: "/pricing"},
{Path: "/blog/hello", LastMod: published},
{Loc: "https://cdn.example.com/guide.pdf"},
}, nil
}})
Path is a path on this app (the provider adds the request's origin); Loc is a full URL. A source that fails is
left out and logged; the rest still answer.
Declare WorksWith: extkit.IDs("sitemapxml/v1"). pb_hooks add URLs with $sitemapXml.add(...) (see
sitemap.xml).
Provide
Implement sitemapxmlv1.Builder: Entries is every URL for a request, private paths left out, and Listed says
whether robots.txt should point at the sitemap (there is one to read). Serve it at /sitemap.xml only when the app
has none of its own.
Extensions
| Extension | |
|---|---|
| sitemap-xml | provides (default) |
| pages | works with |
License
MIT
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.