Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make language merging of markup etc. config without values in the root #10970

Merged
merged 1 commit into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions config/allconfig/allconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,13 @@ func FromLoadConfigResult(fs afero.Fs, res config.LoadConfigResult) (*Configs, e
}
}
} else {
// Apply new values to the root.
differentRootKeys = append(differentRootKeys, "")
switch vv.(type) {
case maps.Params:
differentRootKeys = append(differentRootKeys, kk)
default:
// Apply new values to the root.
differentRootKeys = append(differentRootKeys, "")
}
}
}
differentRootKeys = helpers.UniqueStringsSorted(differentRootKeys)
Expand Down
16 changes: 0 additions & 16 deletions config/allconfig/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,6 @@ func (l configLoader) normalizeCfg(cfg config.Provider) error {
cfg.Set("minify", maps.Params{"minifyOutput": true})
}

// Simplify later merge.
languages := cfg.GetStringMap("languages")
for _, v := range languages {
switch m := v.(type) {
case maps.Params:
// params have merge strategy deep by default.
// The languages config key has strategy none by default.
// This means that if these two sections does not exist on the left side,
// they will not get merged in, so just create some empty maps.
if _, ok := m["params"]; !ok {
m["params"] = maps.Params{}
}
}

}

return nil
}

Expand Down
53 changes: 53 additions & 0 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,59 @@ mainSections: []

}

func TestConfigMergeLanguageDeepEmptyLefSide(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
[params]
p1 = "p1base"
[languages.en]
languageCode = 'en-US'
languageName = 'English'
weight = 1
[languages.en.markup.goldmark.extensions.typographer]
leftDoubleQuote = '“' # default “
rightDoubleQuote = '”' # default ”

[languages.de]
languageCode = 'de-DE'
languageName = 'Deutsch'
weight = 2
[languages.de.params]
p1 = "p1de"
[languages.de.markup.goldmark.extensions.typographer]
leftDoubleQuote = '«' # default “
rightDoubleQuote = '»' # default ”
-- layouts/index.html --
{{ .Content }}
p1: {{ site.Params.p1 }}|
-- content/_index.en.md --
---
title: "English Title"
---
A "quote" in English.
-- content/_index.de.md --
---
title: "Deutsch Title"
---
Ein "Zitat" auf Deutsch.



`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()

b.AssertFileContent("public/index.html", "p1: p1base", "<p>A &ldquo;quote&rdquo; in English.</p>")
b.AssertFileContent("public/de/index.html", "p1: p1de", "<p>Ein &laquo;Zitat&raquo; auf Deutsch.</p>")

}

func TestConfigLegacyValues(t *testing.T) {
t.Parallel()

Expand Down