feat(17-03): sitemap plugin tracer, /sitemap.xml byte-identical to PHP
- golem15.sitemap plugin: golem15_sitemap_definitions migration, Definition model (Fillable theme and data) with tolerant PHP-shaped item decoding and PHP toArray item encoding - Url::to and buildUrl port, libxml-format serializer, generator for url and registry items - GET /sitemap.xml serves the definition with theme default (404 without one, empty body without items) - tests/php/gen-goldens.php and the tracer golden; TestSitemapGolden and the Postgres TestSitemapTracer
This commit is contained in:
44
models/definition.go
Normal file
44
models/definition.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/lagoon"
|
||||
)
|
||||
|
||||
// DefinitionTheme is the fixed theme key of the one sitemap definition of an
|
||||
// application (D-11). The theme column stays so the table matches PHP; the
|
||||
// import commands write this key whatever the PHP theme was.
|
||||
const DefinitionTheme = "default"
|
||||
|
||||
// Definition is a sitemap definition stored on golem15_sitemap_definitions,
|
||||
// the PHP Golem15\Sitemap\Models\Definition. Data holds the items as JSON
|
||||
// text (PHP $jsonable data).
|
||||
type Definition struct {
|
||||
ID uint `gorm:"column:id;primaryKey"`
|
||||
Theme *string `gorm:"column:theme"`
|
||||
Data lagoon.Jsonable[DefinitionItems] `gorm:"column:data"`
|
||||
CreatedAt *time.Time `gorm:"column:created_at"`
|
||||
UpdatedAt *time.Time `gorm:"column:updated_at"`
|
||||
}
|
||||
|
||||
func (Definition) TableName() string { return "golem15_sitemap_definitions" }
|
||||
|
||||
// MorphName is the PHP class string of the model.
|
||||
func (Definition) MorphName() string { return `Golem15\Sitemap\Models\Definition` }
|
||||
|
||||
// Fillable is exactly theme and data, the PHP $fillable with $guarded = ['*']
|
||||
// (MassAssignmentTest).
|
||||
func (Definition) Fillable() []string { return []string{"theme", "data"} }
|
||||
|
||||
// Items returns the stored items.
|
||||
func (d Definition) Items() []DefinitionItem { return d.Data.Get() }
|
||||
|
||||
// SetItems stores items as the definition's data.
|
||||
func (d *Definition) SetItems(items []DefinitionItem) {
|
||||
d.Data = lagoon.Jsonable[DefinitionItems]{Data: DefinitionItems(items), Valid: true}
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(Definition{})
|
||||
}
|
||||
Reference in New Issue
Block a user