Skip to content

Commit 79639c9

Browse files
committed
Fix output formats and media type per language config regression
Fixes #11159
1 parent 9b313ce commit 79639c9

File tree

3 files changed

+80
-31
lines changed

3 files changed

+80
-31
lines changed

config/allconfig/alldecoders.go

+24-8
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ var allDecoderSetups = map[string]decodeWeight{
138138
return err
139139
},
140140
},
141-
"mediaTypes": {
142-
key: "mediaTypes",
141+
"mediatypes": {
142+
key: "mediatypes",
143143
decode: func(d decodeWeight, p decodeConfig) error {
144144
var err error
145145
p.c.MediaTypes, err = media.DecodeTypes(p.p.GetStringMap(d.key))
@@ -168,8 +168,8 @@ var allDecoderSetups = map[string]decodeWeight{
168168
return nil
169169
},
170170
},
171-
"outputFormats": {
172-
key: "outputFormats",
171+
"outputformats": {
172+
key: "outputformats",
173173
decode: func(d decodeWeight, p decodeConfig) error {
174174
var err error
175175
p.c.OutputFormats, err = output.DecodeConfig(p.c.MediaTypes.Config, p.p.Get(d.key))
@@ -221,9 +221,9 @@ var allDecoderSetups = map[string]decodeWeight{
221221
// key = '...'
222222

223223
// To sucessfully be backward compatible, "default" patterns need to be set for both page and term
224-
p.c.Permalinks["page"][k] = v;
225-
p.c.Permalinks["term"][k] = v;
226-
224+
p.c.Permalinks["page"][k] = v
225+
p.c.Permalinks["term"][k] = v
226+
227227
case maps.Params:
228228
// [permalinks.key]
229229
// xyz = ???
@@ -234,7 +234,7 @@ var allDecoderSetups = map[string]decodeWeight{
234234
switch v2 := v2.(type) {
235235
case string:
236236
p.c.Permalinks[k][k2] = v2
237-
237+
238238
default:
239239
return fmt.Errorf("permalinks configuration invalid: unknown value %q for key %q for kind %q", v2, k2, k)
240240
}
@@ -410,3 +410,19 @@ var allDecoderSetups = map[string]decodeWeight{
410410
},
411411
},
412412
}
413+
414+
func init() {
415+
for k, v := range allDecoderSetups {
416+
// Verify that k and v.key is all lower case.
417+
if k != strings.ToLower(k) {
418+
panic(fmt.Sprintf("key %q is not lower case", k))
419+
}
420+
if v.key != strings.ToLower(v.key) {
421+
panic(fmt.Sprintf("key %q is not lower case", v.key))
422+
}
423+
424+
if k != v.key {
425+
panic(fmt.Sprintf("key %q is not the same as the map key %q", k, v.key))
426+
}
427+
}
428+
}

hugolib/config_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,48 @@ LanguageCode: {{ .Site.LanguageCode }}|{{ site.Language.LanguageCode }}|
11441144

11451145
}
11461146

1147+
// See #11159
1148+
func TestConfigOutputFormatsPerLanguage(t *testing.T) {
1149+
t.Parallel()
1150+
1151+
files := `
1152+
-- hugo.toml --
1153+
[languages]
1154+
[languages.en]
1155+
title = "English Title"
1156+
[languages.sv]
1157+
title = "Swedish Title"
1158+
[languages.sv.outputFormats.html]
1159+
path = "foo"
1160+
[languages.sv.mediatypes."text/html"]
1161+
suffixes = ["bar"]
1162+
1163+
-- layouts/index.html --
1164+
Home.
1165+
1166+
1167+
`
1168+
b := NewIntegrationTestBuilder(
1169+
IntegrationTestConfig{
1170+
T: t,
1171+
TxtarString: files,
1172+
},
1173+
).Build()
1174+
1175+
b.AssertFileContent("public/index.html", "Home.")
1176+
1177+
enConfig := b.H.Sites[0].conf
1178+
m, _ := enConfig.MediaTypes.Config.GetByType("text/html")
1179+
b.Assert(m.Suffixes(), qt.DeepEquals, []string{"html"})
1180+
1181+
svConfig := b.H.Sites[1].conf
1182+
f, _ := svConfig.OutputFormats.Config.GetByName("html")
1183+
b.Assert(f.Path, qt.Equals, "foo")
1184+
m, _ = svConfig.MediaTypes.Config.GetByType("text/html")
1185+
b.Assert(m.Suffixes(), qt.DeepEquals, []string{"bar"})
1186+
1187+
}
1188+
11471189
func TestConfigMiscPanics(t *testing.T) {
11481190
t.Parallel()
11491191

tpl/collections/integration_test.go

+14-23
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,16 @@ func TestAppendSliceToASliceOfSlices(t *testing.T) {
8787
8888
{{ $obj }}
8989
90-
9190
`
9291

93-
for i := 0; i < 4; i++ {
94-
95-
b := hugolib.NewIntegrationTestBuilder(
96-
hugolib.IntegrationTestConfig{
97-
T: t,
98-
TxtarString: files,
99-
},
100-
).Build()
101-
102-
b.AssertFileContent("public/index.html", "[[a] [b] [c]]")
92+
b := hugolib.NewIntegrationTestBuilder(
93+
hugolib.IntegrationTestConfig{
94+
T: t,
95+
TxtarString: files,
96+
},
97+
).Build()
10398

104-
}
99+
b.AssertFileContent("public/index.html", "[[a] [b] [c]]")
105100

106101
}
107102

@@ -120,18 +115,14 @@ func TestAppendNilToSlice(t *testing.T) {
120115
121116
`
122117

123-
for i := 0; i < 4; i++ {
124-
125-
b := hugolib.NewIntegrationTestBuilder(
126-
hugolib.IntegrationTestConfig{
127-
T: t,
128-
TxtarString: files,
129-
},
130-
).Build()
131-
132-
b.AssertFileContent("public/index.html", "[a &lt;nil&gt;]")
118+
b := hugolib.NewIntegrationTestBuilder(
119+
hugolib.IntegrationTestConfig{
120+
T: t,
121+
TxtarString: files,
122+
},
123+
).Build()
133124

134-
}
125+
b.AssertFileContent("public/index.html", "[a &lt;nil&gt;]")
135126

136127
}
137128

0 commit comments

Comments
 (0)