mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-23 19:32:10 +00:00
Fix it so languageCode on top level config still works
This is common for monolingual sites, and we broke this in Hugo 0.112.4. Fixes #11037
This commit is contained in:
parent
cd59216de4
commit
e3dfc76fa8
2 changed files with 40 additions and 2 deletions
|
@ -241,8 +241,24 @@ var allDecoderSetups = map[string]decodeWeight{
|
|||
key: "languages",
|
||||
decode: func(d decodeWeight, p decodeConfig) error {
|
||||
var err error
|
||||
p.c.Languages, err = langs.DecodeConfig(p.p.GetStringMap(d.key))
|
||||
return err
|
||||
m := p.p.GetStringMap(d.key)
|
||||
if len(m) == 1 {
|
||||
// In v0.112.4 we moved this to the language config, but it's very commmon for mono language sites to have this at the top level.
|
||||
var first maps.Params
|
||||
for _, v := range m {
|
||||
first = v.(maps.Params)
|
||||
break
|
||||
}
|
||||
if _, found := first["languagecode"]; !found {
|
||||
first["languagecode"] = p.p.GetString("languagecode")
|
||||
}
|
||||
}
|
||||
p.c.Languages, err = langs.DecodeConfig(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
},
|
||||
"cascade": {
|
||||
|
|
|
@ -1044,3 +1044,25 @@ HTACCESS.
|
|||
b.AssertFileContent("public/.htaccess", "HTACCESS")
|
||||
|
||||
}
|
||||
|
||||
func TestConfigLanguageCodeTopLevel(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
languageCode = "en-US"
|
||||
-- layouts/index.html --
|
||||
LanguageCode: {{ .Site.LanguageCode }}|{{ site.Language.LanguageCode }}|
|
||||
|
||||
|
||||
`
|
||||
b := NewIntegrationTestBuilder(
|
||||
IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
).Build()
|
||||
|
||||
b.AssertFileContent("public/index.html", "LanguageCode: en-US|en-US|")
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue