From f4ffeea71dd3d044a2628bbb5d6634680667398f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 22 Aug 2021 11:57:37 +0200 Subject: [PATCH] Fix it so disableKinds etc. does not get merged in from theme 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 --- common/maps/params.go | 8 ++++++++ config/defaultConfigProvider.go | 2 +- config/defaultConfigProvider_test.go | 1 - hugolib/config_test.go | 6 ++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/common/maps/params.go b/common/maps/params.go index c14026df7..15511f56f 100644 --- a/common/maps/params.go +++ b/common/maps/params.go @@ -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() diff --git a/config/defaultConfigProvider.go b/config/defaultConfigProvider.go index 2391ec853..0a10d5cc6 100644 --- a/config/defaultConfigProvider.go +++ b/config/defaultConfigProvider.go @@ -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) } diff --git a/config/defaultConfigProvider_test.go b/config/defaultConfigProvider_test.go index 7ab8c049a..585ce4c67 100644 --- a/config/defaultConfigProvider_test.go +++ b/config/defaultConfigProvider_test.go @@ -172,7 +172,6 @@ func TestDefaultConfigProvider(t *testing.T) { c.Assert(cfg.Get(""), qt.DeepEquals, maps.Params{ "a": "av", - "b": "bv2", }) }) diff --git a/hugolib/config_test.go b/hugolib/config_test.go index bda1c7fb5..8c7d396ef 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -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"] @@ -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",