Files
sm-sitemap-plugin/plugin.go
Jakub Zych 6b67ab759b feat: contract.Rebuilder asks for a debounced rebuild
The sitemap publishes classes.Listing as contract.Rebuilder too, so a
plugin whose Filter reads data of its own can queue the debounced rebuild
a record event queues when that data changes.
2026-11-04 22:39:14 +01:00

90 lines
2.8 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 and contract.Rebuilder
// for other plugins (D-95).
func (p *Plugin) Register(app *backpack.App) error {
p.app = app
if err := app.Publish[contract.Listing](classes.Listing{App: app}); err != nil {
return err
}
return app.Publish[contract.Rebuilder](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{})
}