feat: per-type settings tabs and the SEO tab permission
This commit is contained in:
39
models/type_setting.go
Normal file
39
models/type_setting.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package models
|
||||
|
||||
import "strings"
|
||||
|
||||
// TypeSetting is the per-content-type SEO settings row on
|
||||
// golem15_seo_type_settings (D-104, D-21): whether the SEO tab is shown,
|
||||
// the type's title and description templates, and its default robots.
|
||||
type TypeSetting struct {
|
||||
TypeKey string `gorm:"column:type_key;primaryKey"`
|
||||
Inject bool `gorm:"column:inject"`
|
||||
TitleTemplate string `gorm:"column:title_template"`
|
||||
DescriptionTemplate string `gorm:"column:description_template"`
|
||||
Robots string `gorm:"column:robots"`
|
||||
}
|
||||
|
||||
func (TypeSetting) TableName() string { return "golem15_seo_type_settings" }
|
||||
|
||||
// DefaultTypeRobots is a type's robots before an editor sets one (D-21):
|
||||
// tag archives noindex,follow, author pages index,follow, every other type
|
||||
// empty (the site default).
|
||||
func DefaultTypeRobots(key string) string {
|
||||
k := strings.ToLower(key)
|
||||
switch {
|
||||
case strings.HasSuffix(k, "tag") || strings.HasSuffix(k, "tags"):
|
||||
return "noindex,follow"
|
||||
case strings.HasSuffix(k, "author") || strings.HasSuffix(k, "authors"):
|
||||
return "index,follow"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// DefaultTypeSetting is a type's settings before an editor saves them.
|
||||
func DefaultTypeSetting(key string) TypeSetting {
|
||||
return TypeSetting{TypeKey: key, Inject: true, Robots: DefaultTypeRobots(key)}
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(TypeSetting{})
|
||||
}
|
||||
Reference in New Issue
Block a user