Skip to content

Commit

Permalink
Fix it so disableKinds etc. does not get merged in from theme
Browse files Browse the repository at this point in the history
Unless the merge strategy is set up to do so.

For `disableKinds` the current workaround is to make sure the project config has an entry, even if is empty:

```
disableKinds = []
```

Note that this issue only touches root, non-map config-values that either is not set in project config or in Hugo's defaults.

Fixes #8866
  • Loading branch information
bep committed Aug 22, 2021
1 parent 7ba3f3d commit f4ffeea
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions common/maps/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ func (p Params) Merge(pp Params) {
p.merge("", pp)
}

// MergeRoot transfers values from pp to p for new keys where p is the
// root of the tree.
// This is done recursively.
func (p Params) MergeRoot(pp Params) {
ms, _ := p.GetMergeStrategy()
p.merge(ms, pp)
}

func (p Params) merge(ps ParamsMergeStrategy, pp Params) {
ns, found := p.GetMergeStrategy()

Expand Down
2 changes: 1 addition & 1 deletion config/defaultConfigProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (c *defaultConfigProvider) Merge(k string, v interface{}) {
}
}
// Merge the rest.
c.root.Merge(p)
c.root.MergeRoot(p)
for _, k := range keysToDelete {
delete(c.root, k)
}
Expand Down
1 change: 0 additions & 1 deletion config/defaultConfigProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func TestDefaultConfigProvider(t *testing.T) {

c.Assert(cfg.Get(""), qt.DeepEquals, maps.Params{
"a": "av",
"b": "bv2",
})
})

Expand Down
6 changes: 6 additions & 0 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ name = "menu-top-main"
themeConfig := `
baseURL = "http://bep.is/"
# Can not be set in theme.
disableKinds = ["taxonomy", "term"]
# Can not be set in theme.
[frontmatter]
expiryDate = ["date"]
Expand Down Expand Up @@ -228,6 +231,9 @@ name = "menu-theme"

got := b.Cfg.Get("").(maps.Params)

// Issue #8866
b.Assert(b.Cfg.Get("disableKinds"), qt.IsNil)

b.Assert(got["params"], qt.DeepEquals, maps.Params{
"b": maps.Params{
"b1": "b1 main",
Expand Down

0 comments on commit f4ffeea

Please sign in to comment.