Files
sm-sitemap-plugin/plugin.go
Jakub Zych 4a82240429 feat(17-03): full sitemap generation, settings, hooks and import commands
- generator in Definition::addItemToSet order: 50000 URL cap, lastmod from
  the record or the updates manifest (regular file, 5 MiB cap, fail safe),
  BeforeAddItem (skip) and AddItem (extra XML) festival events, tier or item
  priority, per-alternate expansion of list type children
- priority tiers from golem15.sitemap.priority_tiers, compiled at boot,
  defaults equal to the PHP getPriorityForUrl rules
- frontend_url rewrite of loc, xhtml:link href and the stylesheet href;
  GET /sitemap.xsl serves the PHP stylesheet byte for byte
- golem15_sitemap_settings singleton and Settings model
- sitemap:import (PHP ImportCommand) and sitemap:import-winter with the
  read-only Winter export SQL
- urlto and full goldens generated from PHP; TestSitemapImportSmoke
2026-10-12 17:07:39 +02:00

91 lines
2.5 KiB
Go

// Package sitemap is the golem15.sitemap plugin: it serves /sitemap.xml
// from the application's one sitemap definition, byte for byte the way the
// WinterCMS Golem15.Sitemap plugin did, with items that are explicit URLs
// or menu item types of the framework's registry.
package sitemap
import (
"embed"
"fmt"
"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/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"
"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)
)
//go:embed config
var configFS embed.FS
// sitemapXSL is the PHP plugin's assets/sitemap.xsl, byte for byte.
//
//go:embed assets/sitemap.xsl
var sitemapXSL []byte
// Plugin is the golem15.sitemap plugin.
type Plugin struct {
app *backpack.App
tiers classes.Tiers
}
func (p *Plugin) ID() string { return "golem15.sitemap" }
// Requires is empty: the sitemap reads content types through the framework's
// menu item type registry, not from a named plugin.
func (p *Plugin) Requires() []string { return nil }
func (p *Plugin) Register(app *backpack.App) error {
p.app = app
return nil
}
// Boot compiles the priority tier rules (classes.TiersConfigKey); a rule
// with an unknown setting or a pattern that does not compile fails the boot.
func (p *Plugin) Boot(app *backpack.App) error {
p.app = app
var tiers classes.Tiers
var err error
if app != nil {
tiers, err = classes.LoadTiers(app.Config)
}
if err != nil {
return fmt.Errorf("golem15.sitemap: %w", err)
}
p.tiers = tiers
return nil
}
// ConfigFS ships config/config.yaml: the default priority tier rules.
func (p *Plugin) ConfigFS() fs.FS { return configFS }
// Commands registers sitemap:import and sitemap:import-winter.
func (p *Plugin) Commands() []bonfire.Command {
return []bonfire.Command{
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{})
}