Skip to content

Commit

Permalink
Fix it so languageCode on top level config still works
Browse files Browse the repository at this point in the history
This is common for monolingual sites, and we broke this in Hugo 0.112.4.

Fixes #11037
  • Loading branch information
bep committed May 28, 2023
1 parent cd59216 commit e3dfc76
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
20 changes: 18 additions & 2 deletions config/allconfig/alldecoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
22 changes: 22 additions & 0 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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|")

}

0 comments on commit e3dfc76

Please sign in to comment.