Allow creating home pages from content adapters

* Allow "" (empty string) or "/" to represent the home page path.
* Be a little more lenient about path validation.
This commit is contained in:
Bjørn Erik Pedersen
2025-06-15 11:19:27 +02:00
parent 94e2c276a8
commit bba6996e15
4 changed files with 29 additions and 44 deletions

View File

@@ -149,13 +149,12 @@ var DefaultPageConfig = PageConfig{
Build: DefaultBuildConfig,
}
func (p *PageConfig) Validate(pagesFromData bool) error {
func (p *PageConfig) Init(pagesFromData bool) error {
if pagesFromData {
if p.Path == "" {
return errors.New("path must be set")
}
if strings.HasPrefix(p.Path, "/") {
return fmt.Errorf("path %q must not start with a /", p.Path)
p.Path = strings.TrimPrefix(p.Path, "/")
if p.Path == "" && p.Kind != kinds.KindHome {
return fmt.Errorf("empty path is reserved for the home page")
}
if p.Lang != "" {
return errors.New("lang must not be set")
@@ -295,9 +294,6 @@ type ResourceConfig struct {
}
func (rc *ResourceConfig) Validate() error {
if rc.Path == "" {
return errors.New("path must be set")
}
if rc.Content.Markup != "" {
return errors.New("markup must not be set, use mediaType")
}