feat!: remove the PHP-parity sitemap, tiers, definitions screen and XSL

BREAKING CHANGE: /sitemap.xsl is gone (404), the definitions screen and
the Phase 17 settings tile are replaced by the settings singleton, and
priority, change frequency, priority tiers and the update manifest are
no longer written or read. The config keys golem15.sitemap.cache_seconds
and golem15.sitemap.priority_tiers are removed; site_url, lastmod_ignore
and rebuild_delay_seconds are new.

- sitemap:import and sitemap:import-winter write the additional addresses
  (and site_url, default_locale) instead of the definition
- the golem15_sitemap_definitions table stays in the database, unread
This commit is contained in:
Jakub Zych
2026-11-04 11:12:51 +01:00
parent 3ba70bb69f
commit 84cb27a810
42 changed files with 582 additions and 5371 deletions

View File

@@ -12,50 +12,23 @@ import (
"git.golem15.com/golem15/summercms/modules/lagoon"
)
// errFrontendURL is the phrase key of the frontend_url refusal.
// errFrontendURL is the phrase key of the site address refusal (the
// Phase 17 frontend_url phrase, unchanged).
const errFrontendURL = "golem15.sitemap::lang.errors.frontend_url"
// The settings keys of the five priority tiers, in the order PHP checked
// them. A tier rule names one of them.
const (
PriorityHomepage = "priority_homepage"
PriorityServices = "priority_services"
PriorityBlog = "priority_blog"
PriorityCategories = "priority_categories"
PriorityLegal = "priority_legal"
)
// PriorityDefaults are the PHP defaults of the priority settings.
var PriorityDefaults = map[string]string{
PriorityHomepage: "1.0",
PriorityServices: "0.8",
PriorityBlog: "0.6",
PriorityCategories: "0.4",
PriorityLegal: "0.2",
}
// Settings is the sitemap settings singleton (row id 1) on
// golem15_sitemap_settings, the PHP Golem15\Sitemap\Models\Settings that
// WinterCMS kept in system_settings under golem15_sitemap_settings.
// FrontendURL replaces the backend URL in the generated XML;
// FrontendDefaultLocale is the locale whose URLs carry no prefix;
// UpdatesManifestPath names a JSON file of URL path to last-modified date;
// EnablePriorityTiers turns the tier priorities on, and the priority fields
// hold each tier's value as text. A null priority reads as its PHP default.
// The PHP settings form validated nothing; the port checks FrontendURL in
// BeforeValidate.
// golem15_sitemap_settings (UI-SPEC C26). SiteURL is the public site
// address every <loc> starts with (empty: golem15.sitemap.site_url, then
// app.url), FileSize the addresses per file, DefaultLocale the site's
// default locale (the unprefixed one, and the target of x-default) and
// ExtraURLs the additional addresses. RebuildPendingUntil is the debounce
// time of the next queued rebuild, NumberedSize the file size the files are
// numbered for, BuiltAt the end of the last rebuild and RebuildRequestedAt
// the last rebuild asked for from the admin. The Phase 17 columns
// (frontend_url, priorities, tiers, the update manifest) stay in the table
// and are no longer read (D-32).
type Settings struct {
ID uint `gorm:"column:id;primaryKey"`
FrontendURL *string `gorm:"column:frontend_url"`
FrontendDefaultLocale *string `gorm:"column:frontend_default_locale"`
UpdatesManifestPath *string `gorm:"column:updates_manifest_path"`
EnablePriorityTiers bool `gorm:"column:enable_priority_tiers"`
PriorityHomepage *string `gorm:"column:priority_homepage"`
PriorityServices *string `gorm:"column:priority_services"`
PriorityBlog *string `gorm:"column:priority_blog"`
PriorityCategories *string `gorm:"column:priority_categories"`
PriorityLegal *string `gorm:"column:priority_legal"`
ID uint `gorm:"column:id;primaryKey"`
SiteURL *string `gorm:"column:site_url"`
FileSize int `gorm:"column:file_size"`
DefaultLocale *string `gorm:"column:default_locale"`
@@ -100,8 +73,7 @@ func (Settings) Fillable() []string {
return []string{"site_url", "file_size", "extra_urls"}
}
// Rules is empty: the PHP settings form validated nothing. The one check of
// the port, on frontend_url, is in BeforeValidate.
// Rules is empty: the settings controller runs Validate before a save.
func (Settings) Rules() map[string]string { return map[string]string{} }
// The phrase keys of the other settings refusals.
@@ -127,8 +99,7 @@ func (s Settings) Validate() error {
}
// Problems lists the settings' refusals by field (UI-SPEC C26): a site
// address that AllowedFrontendURL refuses (site_url and the Phase 17
// frontend_url), a file size outside 1..MaxFileSize and an additional
// address that AllowedFrontendURL refuses, a file size outside 1..MaxFileSize and an additional
// address that is not a path or an http(s) URL (extra_urls.<i>.url) or
// whose lastmod is not a date (extra_urls.<i>.lastmod).
func (s Settings) Problems() map[string][]string {
@@ -136,9 +107,6 @@ func (s Settings) Problems() map[string][]string {
if !AllowedFrontendURL(Text(s.SiteURL)) {
out["site_url"] = []string{errFrontendURL}
}
if !AllowedFrontendURL(Text(s.FrontendURL)) {
out["frontend_url"] = []string{errFrontendURL}
}
if s.FileSize < 1 || s.FileSize > MaxFileSize {
out["file_size"] = []string{errFileSize}
}
@@ -153,14 +121,12 @@ func (s Settings) Problems() map[string][]string {
return out
}
// AllowedFrontendURL reports whether u may be the frontend_url setting: the
// empty string, or an absolute http or https URL with a host and without
// whitespace, control characters, a double quote, <, > or &. The PHP plugin
// stored any text. The value is written into every loc, every hreflang link
// and the stylesheet instruction of the sitemap, and sitemap.xsl renders
// each loc as a link on the public origin, so a value outside this form
// (a javascript: URL, or text that closes the attribute it is written into)
// would reach the readers of /sitemap.xml (T-17-15).
// AllowedFrontendURL reports whether u may be the site address: the empty
// string, or an absolute http or https URL with a host and without
// whitespace, control characters, a double quote, <, > or &. The value
// starts every <loc> and hreflang link of the sitemaps, so a value outside
// this form (a javascript: URL, or text that closes the attribute it is
// written into) would reach their readers (T-17-15, T-33-12).
func AllowedFrontendURL(u string) bool {
if u == "" {
return true
@@ -183,32 +149,9 @@ func AllowedFrontendURL(u string) bool {
return parsed.Opaque == "" && parsed.Hostname() != ""
}
// DefaultSettings is the settings PHP read when nothing was saved: tiers on
// with the default priorities.
// DefaultSettings is the settings read when no row is stored.
func DefaultSettings() Settings {
return Settings{ID: 1, EnablePriorityTiers: true, FileSize: DefaultFileSize}
}
// Priority returns the value of a priority setting: the stored text, or the
// PHP default when it is null.
func (s Settings) Priority(key string) string {
var p *string
switch key {
case PriorityHomepage:
p = s.PriorityHomepage
case PriorityServices:
p = s.PriorityServices
case PriorityBlog:
p = s.PriorityBlog
case PriorityCategories:
p = s.PriorityCategories
case PriorityLegal:
p = s.PriorityLegal
}
if p == nil {
return PriorityDefaults[key]
}
return *p
return Settings{ID: 1, FileSize: DefaultFileSize}
}
func init() {