mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 22:21:07 +03:00
Fix config merge regression with root slices (e.g. disableKinds)
Fixes #11089
This commit is contained in:
parent
e08cfc8ca0
commit
60a2cdf72d
2 changed files with 86 additions and 0 deletions
|
@ -191,6 +191,22 @@ type configCompiler interface {
|
||||||
func (c Config) cloneForLang() *Config {
|
func (c Config) cloneForLang() *Config {
|
||||||
x := c
|
x := c
|
||||||
x.C = nil
|
x.C = nil
|
||||||
|
copyStringSlice := func(in []string) []string {
|
||||||
|
if in == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
out := make([]string, len(in))
|
||||||
|
copy(out, in)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy all the slices to avoid sharing.
|
||||||
|
x.DisableKinds = copyStringSlice(x.DisableKinds)
|
||||||
|
x.DisableLanguages = copyStringSlice(x.DisableLanguages)
|
||||||
|
x.MainSections = copyStringSlice(x.MainSections)
|
||||||
|
x.IgnoreErrors = copyStringSlice(x.IgnoreErrors)
|
||||||
|
x.IgnoreFiles = copyStringSlice(x.IgnoreFiles)
|
||||||
|
x.Theme = copyStringSlice(x.Theme)
|
||||||
|
|
||||||
// Collapse all static dirs to one.
|
// Collapse all static dirs to one.
|
||||||
x.StaticDir = x.staticDirs()
|
x.StaticDir = x.staticDirs()
|
||||||
|
@ -787,12 +803,14 @@ func fromLoadConfigResult(fs afero.Fs, logger loggers.Logger, res config.LoadCon
|
||||||
|
|
||||||
// Create a copy of the complete config and replace the root keys with the language specific ones.
|
// Create a copy of the complete config and replace the root keys with the language specific ones.
|
||||||
clone := all.cloneForLang()
|
clone := all.cloneForLang()
|
||||||
|
|
||||||
if err := decodeConfigFromParams(fs, bcfg, mergedConfig, clone, differentRootKeys); err != nil {
|
if err := decodeConfigFromParams(fs, bcfg, mergedConfig, clone, differentRootKeys); err != nil {
|
||||||
return nil, fmt.Errorf("failed to decode config for language %q: %w", k, err)
|
return nil, fmt.Errorf("failed to decode config for language %q: %w", k, err)
|
||||||
}
|
}
|
||||||
if err := clone.CompileConfig(logger); err != nil {
|
if err := clone.CompileConfig(logger); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
langConfigMap[k] = clone
|
langConfigMap[k] = clone
|
||||||
case maps.ParamsMergeStrategy:
|
case maps.ParamsMergeStrategy:
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -750,6 +750,74 @@ author: {{ site.Author }}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #11089
|
||||||
|
func TestHugoConfigSliceOverrides(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
filesTemplate := `
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ["section"]
|
||||||
|
[languages]
|
||||||
|
[languages.en]
|
||||||
|
disableKinds = []
|
||||||
|
title = "English"
|
||||||
|
weigHt = WEIGHT_EN
|
||||||
|
[languages.sv]
|
||||||
|
title = "Swedish"
|
||||||
|
wEight = WEIGHT_SV
|
||||||
|
disableKinds = ["page"]
|
||||||
|
-- layouts/index.html --
|
||||||
|
Home: {{ .Lang}}|{{ len site.RegularPages }}|
|
||||||
|
-- layouts/_default/single.html --
|
||||||
|
Single.
|
||||||
|
-- content/p1.en.md --
|
||||||
|
-- content/p2.en.md --
|
||||||
|
-- content/p1.sv.md --
|
||||||
|
-- content/p2.sv.md --
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
t.Run("En first", func(t *testing.T) {
|
||||||
|
files := strings.ReplaceAll(filesTemplate, "WEIGHT_EN", "1")
|
||||||
|
files = strings.ReplaceAll(files, "WEIGHT_SV", "2")
|
||||||
|
|
||||||
|
cfg := config.New()
|
||||||
|
b, err := NewIntegrationTestBuilder(
|
||||||
|
IntegrationTestConfig{
|
||||||
|
T: t,
|
||||||
|
TxtarString: files,
|
||||||
|
BaseCfg: cfg,
|
||||||
|
},
|
||||||
|
).BuildE()
|
||||||
|
|
||||||
|
b.Assert(err, qt.IsNil)
|
||||||
|
b.AssertFileContent("public/index.html", "Home: en|2|")
|
||||||
|
b.AssertFileContent("public/sv/index.html", "Home: sv|0|")
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Sv first", func(t *testing.T) {
|
||||||
|
files := strings.ReplaceAll(filesTemplate, "WEIGHT_EN", "2")
|
||||||
|
files = strings.ReplaceAll(files, "WEIGHT_SV", "1")
|
||||||
|
|
||||||
|
for i := 0; i < 20; i++ {
|
||||||
|
cfg := config.New()
|
||||||
|
b, err := NewIntegrationTestBuilder(
|
||||||
|
IntegrationTestConfig{
|
||||||
|
T: t,
|
||||||
|
TxtarString: files,
|
||||||
|
BaseCfg: cfg,
|
||||||
|
},
|
||||||
|
).BuildE()
|
||||||
|
|
||||||
|
b.Assert(err, qt.IsNil)
|
||||||
|
b.AssertFileContent("public/index.html", "Home: en|2|")
|
||||||
|
b.AssertFileContent("public/sv/index.html", "Home: sv|0|")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestConfigOutputFormatDefinedInTheme(t *testing.T) {
|
func TestConfigOutputFormatDefinedInTheme(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue