- one settings tile opening the golem15.sitemap.settings singleton - Files tab (site address, file size, S1 files partial), Additional addresses repeater, Content types tab built from signpost at boot - golem15_sitemap_types; a type switched off leaves the files (reason type) - a save validates (errors.*) and dispatches a rebuild after commit
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package classes
|
|
|
|
import (
|
|
"git.golem15.com/golem15/sm-sitemap-plugin/models"
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// ReservedSlugs are file name parts no content type may use: the image
|
|
// and News sitemaps own them.
|
|
var ReservedSlugs = map[string]bool{"images": true, "news": true}
|
|
|
|
// TypeConfig is a content type's effective sitemap setting: its key and
|
|
// label, whether its records are listed, its group slug and its HTML
|
|
// sitemap headings (nil when none was saved).
|
|
type TypeConfig struct {
|
|
Key string
|
|
Label string
|
|
Include bool
|
|
Slug string
|
|
Titles map[string]string
|
|
}
|
|
|
|
// LoadTypeSettings reads the saved content type settings by type key.
|
|
func LoadTypeSettings(db *gorm.DB) (map[string]models.TypeSetting, error) {
|
|
var rows []models.TypeSetting
|
|
if err := db.Find(&rows).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
out := make(map[string]models.TypeSetting, len(rows))
|
|
for _, r := range rows {
|
|
out[r.TypeKey] = r
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// EffectiveType is the setting of typ: the saved row, else listed under
|
|
// DefaultSlug. A saved slug that is not a ValidSlug falls back to the
|
|
// default.
|
|
func EffectiveType(typ pact.MenuItemType, rows map[string]models.TypeSetting) TypeConfig {
|
|
cfg := TypeConfig{Key: typ.Key, Label: typ.Label, Include: true, Slug: DefaultSlug(typ.Key)}
|
|
row, ok := rows[typ.Key]
|
|
if !ok {
|
|
return cfg
|
|
}
|
|
cfg.Include = row.Include
|
|
if ValidSlug(row.Slug) {
|
|
cfg.Slug = row.Slug
|
|
}
|
|
if titles := row.Titles.Get(); len(titles) > 0 {
|
|
cfg.Titles = titles
|
|
}
|
|
return cfg
|
|
}
|