mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Fix output formats and media type per language config regression
Fixes #11159
This commit is contained in:
parent
9b313cec1b
commit
79639c981c
3 changed files with 80 additions and 31 deletions
|
@ -138,8 +138,8 @@ var allDecoderSetups = map[string]decodeWeight{
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"mediaTypes": {
|
"mediatypes": {
|
||||||
key: "mediaTypes",
|
key: "mediatypes",
|
||||||
decode: func(d decodeWeight, p decodeConfig) error {
|
decode: func(d decodeWeight, p decodeConfig) error {
|
||||||
var err error
|
var err error
|
||||||
p.c.MediaTypes, err = media.DecodeTypes(p.p.GetStringMap(d.key))
|
p.c.MediaTypes, err = media.DecodeTypes(p.p.GetStringMap(d.key))
|
||||||
|
@ -168,8 +168,8 @@ var allDecoderSetups = map[string]decodeWeight{
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"outputFormats": {
|
"outputformats": {
|
||||||
key: "outputFormats",
|
key: "outputformats",
|
||||||
decode: func(d decodeWeight, p decodeConfig) error {
|
decode: func(d decodeWeight, p decodeConfig) error {
|
||||||
var err error
|
var err error
|
||||||
p.c.OutputFormats, err = output.DecodeConfig(p.c.MediaTypes.Config, p.p.Get(d.key))
|
p.c.OutputFormats, err = output.DecodeConfig(p.c.MediaTypes.Config, p.p.Get(d.key))
|
||||||
|
@ -221,9 +221,9 @@ var allDecoderSetups = map[string]decodeWeight{
|
||||||
// key = '...'
|
// key = '...'
|
||||||
|
|
||||||
// To sucessfully be backward compatible, "default" patterns need to be set for both page and term
|
// To sucessfully be backward compatible, "default" patterns need to be set for both page and term
|
||||||
p.c.Permalinks["page"][k] = v;
|
p.c.Permalinks["page"][k] = v
|
||||||
p.c.Permalinks["term"][k] = v;
|
p.c.Permalinks["term"][k] = v
|
||||||
|
|
||||||
case maps.Params:
|
case maps.Params:
|
||||||
// [permalinks.key]
|
// [permalinks.key]
|
||||||
// xyz = ???
|
// xyz = ???
|
||||||
|
@ -234,7 +234,7 @@ var allDecoderSetups = map[string]decodeWeight{
|
||||||
switch v2 := v2.(type) {
|
switch v2 := v2.(type) {
|
||||||
case string:
|
case string:
|
||||||
p.c.Permalinks[k][k2] = v2
|
p.c.Permalinks[k][k2] = v2
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("permalinks configuration invalid: unknown value %q for key %q for kind %q", v2, k2, k)
|
return fmt.Errorf("permalinks configuration invalid: unknown value %q for key %q for kind %q", v2, k2, k)
|
||||||
}
|
}
|
||||||
|
@ -410,3 +410,19 @@ var allDecoderSetups = map[string]decodeWeight{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
for k, v := range allDecoderSetups {
|
||||||
|
// Verify that k and v.key is all lower case.
|
||||||
|
if k != strings.ToLower(k) {
|
||||||
|
panic(fmt.Sprintf("key %q is not lower case", k))
|
||||||
|
}
|
||||||
|
if v.key != strings.ToLower(v.key) {
|
||||||
|
panic(fmt.Sprintf("key %q is not lower case", v.key))
|
||||||
|
}
|
||||||
|
|
||||||
|
if k != v.key {
|
||||||
|
panic(fmt.Sprintf("key %q is not the same as the map key %q", k, v.key))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1144,6 +1144,48 @@ LanguageCode: {{ .Site.LanguageCode }}|{{ site.Language.LanguageCode }}|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See #11159
|
||||||
|
func TestConfigOutputFormatsPerLanguage(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
[languages]
|
||||||
|
[languages.en]
|
||||||
|
title = "English Title"
|
||||||
|
[languages.sv]
|
||||||
|
title = "Swedish Title"
|
||||||
|
[languages.sv.outputFormats.html]
|
||||||
|
path = "foo"
|
||||||
|
[languages.sv.mediatypes."text/html"]
|
||||||
|
suffixes = ["bar"]
|
||||||
|
|
||||||
|
-- layouts/index.html --
|
||||||
|
Home.
|
||||||
|
|
||||||
|
|
||||||
|
`
|
||||||
|
b := NewIntegrationTestBuilder(
|
||||||
|
IntegrationTestConfig{
|
||||||
|
T: t,
|
||||||
|
TxtarString: files,
|
||||||
|
},
|
||||||
|
).Build()
|
||||||
|
|
||||||
|
b.AssertFileContent("public/index.html", "Home.")
|
||||||
|
|
||||||
|
enConfig := b.H.Sites[0].conf
|
||||||
|
m, _ := enConfig.MediaTypes.Config.GetByType("text/html")
|
||||||
|
b.Assert(m.Suffixes(), qt.DeepEquals, []string{"html"})
|
||||||
|
|
||||||
|
svConfig := b.H.Sites[1].conf
|
||||||
|
f, _ := svConfig.OutputFormats.Config.GetByName("html")
|
||||||
|
b.Assert(f.Path, qt.Equals, "foo")
|
||||||
|
m, _ = svConfig.MediaTypes.Config.GetByType("text/html")
|
||||||
|
b.Assert(m.Suffixes(), qt.DeepEquals, []string{"bar"})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestConfigMiscPanics(t *testing.T) {
|
func TestConfigMiscPanics(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
|
@ -87,21 +87,16 @@ func TestAppendSliceToASliceOfSlices(t *testing.T) {
|
||||||
|
|
||||||
{{ $obj }}
|
{{ $obj }}
|
||||||
|
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
for i := 0; i < 4; i++ {
|
b := hugolib.NewIntegrationTestBuilder(
|
||||||
|
hugolib.IntegrationTestConfig{
|
||||||
|
T: t,
|
||||||
|
TxtarString: files,
|
||||||
|
},
|
||||||
|
).Build()
|
||||||
|
|
||||||
b := hugolib.NewIntegrationTestBuilder(
|
b.AssertFileContent("public/index.html", "[[a] [b] [c]]")
|
||||||
hugolib.IntegrationTestConfig{
|
|
||||||
T: t,
|
|
||||||
TxtarString: files,
|
|
||||||
},
|
|
||||||
).Build()
|
|
||||||
|
|
||||||
b.AssertFileContent("public/index.html", "[[a] [b] [c]]")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,18 +115,14 @@ func TestAppendNilToSlice(t *testing.T) {
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
for i := 0; i < 4; i++ {
|
b := hugolib.NewIntegrationTestBuilder(
|
||||||
|
hugolib.IntegrationTestConfig{
|
||||||
|
T: t,
|
||||||
|
TxtarString: files,
|
||||||
|
},
|
||||||
|
).Build()
|
||||||
|
|
||||||
b := hugolib.NewIntegrationTestBuilder(
|
b.AssertFileContent("public/index.html", "[a <nil>]")
|
||||||
hugolib.IntegrationTestConfig{
|
|
||||||
T: t,
|
|
||||||
TxtarString: files,
|
|
||||||
},
|
|
||||||
).Build()
|
|
||||||
|
|
||||||
b.AssertFileContent("public/index.html", "[a <nil>]")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue