summaryrefslogtreecommitdiffstats
path: root/resources/page/page_matcher.go
diff options
context:
space:
mode:
Diffstat (limited to 'resources/page/page_matcher.go')
-rw-r--r--resources/page/page_matcher.go39
1 files changed, 33 insertions, 6 deletions
diff --git a/resources/page/page_matcher.go b/resources/page/page_matcher.go
index 1e98b0836..27a7c7e9e 100644
--- a/resources/page/page_matcher.go
+++ b/resources/page/page_matcher.go
@@ -16,6 +16,7 @@ package page
import (
"fmt"
"path/filepath"
+ "slices"
"strings"
"github.com/gohugoio/hugo/common/loggers"
@@ -24,7 +25,6 @@ import (
"github.com/gohugoio/hugo/hugofs/glob"
"github.com/gohugoio/hugo/resources/kinds"
"github.com/mitchellh/mapstructure"
- "slices"
)
// A PageMatcher can be used to match a Page with Glob patterns.
@@ -105,7 +105,7 @@ func CheckCascadePattern(logger loggers.Logger, m PageMatcher) {
}
}
-func DecodeCascadeConfig(logger loggers.Logger, in any) (*config.ConfigNamespace[[]PageMatcherParamsConfig, *maps.Ordered[PageMatcher, maps.Params]], error) {
+func DecodeCascadeConfig(logger loggers.Logger, handleLegacyFormat bool, in any) (*config.ConfigNamespace[[]PageMatcherParamsConfig, *maps.Ordered[PageMatcher, maps.Params]], error) {
buildConfig := func(in any) (*maps.Ordered[PageMatcher, maps.Params], any, error) {
cascade := maps.NewOrdered[PageMatcher, maps.Params]()
if in == nil {
@@ -120,7 +120,15 @@ func DecodeCascadeConfig(logger loggers.Logger, in any) (*config.ConfigNamespace
for _, m := range ms {
m = maps.CleanConfigStringMap(m)
- c, err := mapToPageMatcherParamsConfig(m)
+ var (
+ c PageMatcherParamsConfig
+ err error
+ )
+ if handleLegacyFormat {
+ c, err = mapToPageMatcherParamsConfigLegacy(m)
+ } else {
+ c, err = mapToPageMatcherParamsConfig(m)
+ }
if err != nil {
return nil, nil, err
}
@@ -155,8 +163,8 @@ func DecodeCascadeConfig(logger loggers.Logger, in any) (*config.ConfigNamespace
}
// DecodeCascade decodes in which could be either a map or a slice of maps.
-func DecodeCascade(logger loggers.Logger, in any) (*maps.Ordered[PageMatcher, maps.Params], error) {
- conf, err := DecodeCascadeConfig(logger, in)
+func DecodeCascade(logger loggers.Logger, handleLegacyFormat bool, in any) (*maps.Ordered[PageMatcher, maps.Params], error) {
+ conf, err := DecodeCascadeConfig(logger, handleLegacyFormat, in)
if err != nil {
return nil, err
}
@@ -167,6 +175,26 @@ func mapToPageMatcherParamsConfig(m map[string]any) (PageMatcherParamsConfig, er
var pcfg PageMatcherParamsConfig
for k, v := range m {
switch strings.ToLower(k) {
+ case "_target", "target":
+ var target PageMatcher
+ if err := decodePageMatcher(v, &target); err != nil {
+ return pcfg, err
+ }
+ pcfg.Target = target
+ default:
+ if pcfg.Params == nil {
+ pcfg.Params = make(maps.Params)
+ }
+ pcfg.Params[k] = v
+ }
+ }
+ return pcfg, pcfg.init()
+}
+
+func mapToPageMatcherParamsConfigLegacy(m map[string]any) (PageMatcherParamsConfig, error) {
+ var pcfg PageMatcherParamsConfig
+ for k, v := range m {
+ switch strings.ToLower(k) {
case "params":
// We simplified the structure of the cascade config in Hugo 0.111.0.
// There is a small chance that someone has used the old structure with the params keyword,
@@ -190,7 +218,6 @@ func mapToPageMatcherParamsConfig(m map[string]any) (PageMatcherParamsConfig, er
}
pcfg.Target = target
default:
- // Legacy config.
if pcfg.Params == nil {
pcfg.Params = make(maps.Params)
}