diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-05-17 16:29:06 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-05-17 22:13:29 +0200 |
commit | 7ce033a89d411036e40dbb42325e30e12248bda9 (patch) | |
tree | e0731bdb59645393c05a3cfe22c0bf90e09c14c9 /common/maps | |
parent | 05542130ba0205d3d8d14575b7e49ed42a855b9a (diff) | |
download | hugo-7ce033a89d411036e40dbb42325e30e12248bda9.tar.gz hugo-7ce033a89d411036e40dbb42325e30e12248bda9.zip |
Support, but warn, about top level language custom params
Updates #10947
Diffstat (limited to 'common/maps')
-rw-r--r-- | common/maps/params.go | 24 | ||||
-rw-r--r-- | common/maps/params_test.go | 4 |
2 files changed, 14 insertions, 14 deletions
diff --git a/common/maps/params.go b/common/maps/params.go index eb60fbbfc..a3e607b89 100644 --- a/common/maps/params.go +++ b/common/maps/params.go @@ -70,7 +70,7 @@ func (p Params) IsZero() bool { } for k := range p { - return k == mergeStrategyKey + return k == MergeStrategyKey } return false @@ -103,7 +103,7 @@ func (p Params) merge(ps ParamsMergeStrategy, pp Params) { for k, v := range pp { - if k == mergeStrategyKey { + if k == MergeStrategyKey { continue } vv, found := p[k] @@ -124,7 +124,7 @@ func (p Params) merge(ps ParamsMergeStrategy, pp Params) { // For internal use. func (p Params) GetMergeStrategy() (ParamsMergeStrategy, bool) { - if v, found := p[mergeStrategyKey]; found { + if v, found := p[MergeStrategyKey]; found { if s, ok := v.(ParamsMergeStrategy); ok { return s, true } @@ -134,8 +134,8 @@ func (p Params) GetMergeStrategy() (ParamsMergeStrategy, bool) { // For internal use. func (p Params) DeleteMergeStrategy() bool { - if _, found := p[mergeStrategyKey]; found { - delete(p, mergeStrategyKey) + if _, found := p[MergeStrategyKey]; found { + delete(p, MergeStrategyKey) return true } return false @@ -148,7 +148,7 @@ func (p Params) SetMergeStrategy(s ParamsMergeStrategy) { default: panic(fmt.Sprintf("invalid merge strategy %q", s)) } - p[mergeStrategyKey] = s + p[MergeStrategyKey] = s } func getNested(m map[string]any, indices []string) (any, string, map[string]any) { @@ -242,7 +242,7 @@ const ( // Add new keys, merge existing. ParamsMergeStrategyDeep ParamsMergeStrategy = "deep" - mergeStrategyKey = "_merge" + MergeStrategyKey = "_merge" ) // CleanConfigStringMapString removes any processing instructions from m, @@ -251,13 +251,13 @@ func CleanConfigStringMapString(m map[string]string) map[string]string { if m == nil || len(m) == 0 { return m } - if _, found := m[mergeStrategyKey]; !found { + if _, found := m[MergeStrategyKey]; !found { return m } // Create a new map and copy all the keys except the merge strategy key. m2 := make(map[string]string, len(m)-1) for k, v := range m { - if k != mergeStrategyKey { + if k != MergeStrategyKey { m2[k] = v } } @@ -270,13 +270,13 @@ func CleanConfigStringMap(m map[string]any) map[string]any { if m == nil || len(m) == 0 { return m } - if _, found := m[mergeStrategyKey]; !found { + if _, found := m[MergeStrategyKey]; !found { return m } // Create a new map and copy all the keys except the merge strategy key. m2 := make(map[string]any, len(m)-1) for k, v := range m { - if k != mergeStrategyKey { + if k != MergeStrategyKey { m2[k] = v } switch v2 := v.(type) { @@ -313,7 +313,7 @@ func PrepareParams(m Params) { for k, v := range m { var retyped bool lKey := strings.ToLower(k) - if lKey == mergeStrategyKey { + if lKey == MergeStrategyKey { v = toMergeStrategy(v) retyped = true } else { diff --git a/common/maps/params_test.go b/common/maps/params_test.go index 7e1dbbae7..578b2a576 100644 --- a/common/maps/params_test.go +++ b/common/maps/params_test.go @@ -75,7 +75,7 @@ func TestParamsSetAndMerge(t *testing.T) { createParamsPair := func() (Params, Params) { p1 := Params{"a": "av", "c": "cv", "nested": Params{"al2": "al2v", "cl2": "cl2v"}} - p2 := Params{"b": "bv", "a": "abv", "nested": Params{"bl2": "bl2v", "al2": "al2bv"}, mergeStrategyKey: ParamsMergeStrategyDeep} + p2 := Params{"b": "bv", "a": "abv", "nested": Params{"bl2": "bl2v", "al2": "al2bv"}, MergeStrategyKey: ParamsMergeStrategyDeep} return p1, p2 } @@ -92,7 +92,7 @@ func TestParamsSetAndMerge(t *testing.T) { "bl2": "bl2v", }, "b": "bv", - mergeStrategyKey: ParamsMergeStrategyDeep, + MergeStrategyKey: ParamsMergeStrategyDeep, }) p1, p2 = createParamsPair() |