Files
sm-sitemap-plugin/plugin.go
Jakub Zych ded1095c39 feat: hreflang alternates and the sitemap filter contract
- every listed address of a record with more than one listed locale
  carries xhtml:link alternates for each locale plus x-default on the
  default locale (D-55 to D-57); no alternate for a missing translation
- each page of records and the additional addresses go to the published
  contract.Filter in one batch: Exclude leaves the files with its reason,
  Group moves the address, LastMod seeds a new row (D-95, D-24)
- classes.Listing implements contract.Listing and is published in Register
2026-11-04 11:20:38 +01:00

87 lines
2.7 KiB
Go

// Package sitemap is the golem15.sitemap plugin: it serves a sitemap index
// at /sitemap.xml whose entries are per-group files of a configurable size
// (sitemap-<slug>-<n>.xml, D-30), built from the published records of every
// signpost content type and the additional addresses of its settings, with
// stable file numbers and real lastmod. Other plugins narrow it through the
// Filter of the contract package and read it through its Listing.
package sitemap
import (
"embed"
"io/fs"
"git.golem15.com/golem15/sm-sitemap-plugin/classes"
"git.golem15.com/golem15/sm-sitemap-plugin/console"
"git.golem15.com/golem15/sm-sitemap-plugin/contract"
"git.golem15.com/golem15/sm-sitemap-plugin/models"
"git.golem15.com/golem15/sm-sitemap-plugin/updates"
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/modules/pact"
"git.golem15.com/golem15/summercms/modules/party"
"git.golem15.com/golem15/summercms/modules/surf"
"github.com/go-gormigrate/gormigrate/v2"
)
var (
_ party.Plugin = (*Plugin)(nil)
_ pact.HasConfig = (*Plugin)(nil)
_ pact.HasMigrations = (*Plugin)(nil)
_ pact.HasModels = (*Plugin)(nil)
_ pact.HasRoutes = (*Plugin)(nil)
_ pact.HasCommands = (*Plugin)(nil)
_ pact.HasJobs = (*Plugin)(nil)
_ surf.BucketProvider = (*Plugin)(nil)
)
//go:embed config
var configFS embed.FS
// Plugin is the golem15.sitemap plugin.
type Plugin struct {
app *backpack.App
}
func (p *Plugin) ID() string { return "golem15.sitemap" }
// Requires is empty: the sitemap reads content types through signpost, not
// from a named plugin, and a Filter through the service registry.
func (p *Plugin) Requires() []string { return nil }
// Register publishes the sitemap's contract.Listing for other plugins
// (D-95).
func (p *Plugin) Register(app *backpack.App) error {
p.app = app
return app.Publish[contract.Listing](classes.Listing{App: app})
}
// Boot keeps the booted application for the routes, jobs and commands and
// subscribes to the record events.
func (p *Plugin) Boot(app *backpack.App) error {
p.app = app
p.listen(app)
return nil
}
// ConfigFS ships config/config.yaml: lastmod_ignore and
// rebuild_delay_seconds.
func (p *Plugin) ConfigFS() fs.FS { return configFS }
// Commands registers sitemap:rebuild, sitemap:import and
// sitemap:import-winter.
func (p *Plugin) Commands() []bonfire.Command {
return []bonfire.Command{
console.Rebuild(p.app),
console.Import(p.app),
console.ImportWinter(p.app),
}
}
func (p *Plugin) Migrations() []*gormigrate.Migration { return updates.All() }
func (p *Plugin) Models() []any { return models.All() }
func init() {
party.Register(&Plugin{})
}