mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
a7d6b1413f
commit
6462eecfbd
3 changed files with 60 additions and 16 deletions
|
@ -245,12 +245,17 @@ var allDecoderSetups = map[string]decodeWeight{
|
||||||
if len(m) == 1 {
|
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.
|
// 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
|
var first maps.Params
|
||||||
|
var ok bool
|
||||||
for _, v := range m {
|
for _, v := range m {
|
||||||
first = v.(maps.Params)
|
first, ok = v.(maps.Params)
|
||||||
break
|
if ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if _, found := first["languagecode"]; !found {
|
if first != nil {
|
||||||
first["languagecode"] = p.p.GetString("languagecode")
|
if _, found := first["languagecode"]; !found {
|
||||||
|
first["languagecode"] = p.p.GetString("languagecode")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.c.Languages, err = langs.DecodeConfig(m)
|
p.c.Languages, err = langs.DecodeConfig(m)
|
||||||
|
|
|
@ -1067,25 +1067,59 @@ LanguageCode: {{ .Site.LanguageCode }}|{{ site.Language.LanguageCode }}|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue 11047
|
func TestConfigMiscPanics(t *testing.T) {
|
||||||
func TestConfigYamlNil(t *testing.T) {
|
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
files := `
|
// Issue 11047,
|
||||||
|
t.Run("empty params", func(t *testing.T) {
|
||||||
|
|
||||||
|
files := `
|
||||||
-- hugo.yaml --
|
-- hugo.yaml --
|
||||||
params:
|
params:
|
||||||
-- layouts/index.html --
|
-- layouts/index.html --
|
||||||
Foo: {{ site.Params.foo }}|
|
Foo: {{ site.Params.foo }}|
|
||||||
|
|
||||||
|
|
||||||
`
|
`
|
||||||
b := NewIntegrationTestBuilder(
|
b := NewIntegrationTestBuilder(
|
||||||
IntegrationTestConfig{
|
IntegrationTestConfig{
|
||||||
T: t,
|
T: t,
|
||||||
TxtarString: files,
|
TxtarString: files,
|
||||||
},
|
},
|
||||||
).Build()
|
).Build()
|
||||||
|
|
||||||
b.AssertFileContent("public/index.html", "Foo: |")
|
b.AssertFileContent("public/index.html", "Foo: |")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Issue 11046
|
||||||
|
t.Run("invalid language setup", func(t *testing.T) {
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
baseURL = "https://example.org"
|
||||||
|
languageCode = "en-us"
|
||||||
|
title = "Blog of me"
|
||||||
|
defaultContentLanguage = "en"
|
||||||
|
|
||||||
|
[languages]
|
||||||
|
[en]
|
||||||
|
lang = "en"
|
||||||
|
languageName = "English"
|
||||||
|
weight = 1
|
||||||
|
-- layouts/index.html --
|
||||||
|
Foo: {{ site.Params.foo }}|
|
||||||
|
|
||||||
|
|
||||||
|
`
|
||||||
|
b, err := NewIntegrationTestBuilder(
|
||||||
|
IntegrationTestConfig{
|
||||||
|
T: t,
|
||||||
|
TxtarString: files,
|
||||||
|
},
|
||||||
|
).BuildE()
|
||||||
|
|
||||||
|
b.Assert(err, qt.IsNotNil)
|
||||||
|
b.Assert(err.Error(), qt.Contains, "no languages")
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
package langs
|
package langs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/common/maps"
|
"github.com/gohugoio/hugo/common/maps"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
)
|
)
|
||||||
|
@ -46,5 +48,8 @@ func DecodeConfig(m map[string]any) (map[string]LanguageConfig, error) {
|
||||||
if err := mapstructure.WeakDecode(m, &langs); err != nil {
|
if err := mapstructure.WeakDecode(m, &langs); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if len(langs) == 0 {
|
||||||
|
return nil, errors.New("no languages configured")
|
||||||
|
}
|
||||||
return langs, nil
|
return langs, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue