// 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" "time" "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" "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) _ surf.BucketProvider = (*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 cache *sitemapCache } 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. // It also starts an empty sitemap cache for CacheConfigKey seconds; a // negative value fails the boot. func (p *Plugin) Boot(app *backpack.App) error { p.app = app var tiers classes.Tiers var err error seconds := 0 if app != nil { tiers, err = classes.LoadTiers(app.Config) if app.Config != nil { seconds = app.Config.Int(CacheConfigKey) } } if err != nil { return fmt.Errorf("golem15.sitemap: %w", err) } if seconds < 0 { return fmt.Errorf("golem15.sitemap: %s must not be negative, got %d", CacheConfigKey, seconds) } p.tiers = tiers p.cache = newSitemapCache(time.Duration(seconds) * time.Second) 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{}) }