Skip to content

Commit 1c114d5

Browse files
committed
hugolib: Do not tolower result from Page.GetParam
We still do lowering of the param strings in some internal use of this, but the exported `GetParam` method is changed to a more sensible default. This was used for the `disqus_title` etc. in the internal Disqus template, which was obviously not right. If you really want to lowercase your params, do it with `.GetParam "myparam" | lower` or similar. Fixes #4187
1 parent e141294 commit 1c114d5

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

hugolib/page.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ func (p *Page) renderContent(content []byte) []byte {
714714

715715
func (p *Page) getRenderingConfig() *helpers.BlackFriday {
716716
p.renderingConfigInit.Do(func() {
717-
bfParam := p.GetParam("blackfriday")
717+
bfParam := p.getParamToLower("blackfriday")
718718
if bfParam == nil {
719719
p.renderingConfig = p.s.ContentSpec.BlackFriday
720720
return
@@ -1306,6 +1306,10 @@ func (p *Page) update(f interface{}) error {
13061306
}
13071307

13081308
func (p *Page) GetParam(key string) interface{} {
1309+
return p.getParam(key, false)
1310+
}
1311+
1312+
func (p *Page) getParamToLower(key string) interface{} {
13091313
return p.getParam(key, true)
13101314
}
13111315

hugolib/pageGroup.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (p Pages) GroupByParam(key string, order ...string) (PagesGroup, error) {
167167
var tmp reflect.Value
168168
var keyt reflect.Type
169169
for _, e := range p {
170-
param := e.GetParam(key)
170+
param := e.getParamToLower(key)
171171
if param != nil {
172172
if _, ok := param.([]string); !ok {
173173
keyt = reflect.TypeOf(param)
@@ -278,21 +278,21 @@ func (p Pages) GroupByParamDate(key string, format string, order ...string) (Pag
278278
sorter := func(p Pages) Pages {
279279
var r Pages
280280
for _, e := range p {
281-
param := e.GetParam(key)
281+
param := e.getParamToLower(key)
282282
if param != nil {
283283
if _, ok := param.(time.Time); ok {
284284
r = append(r, e)
285285
}
286286
}
287287
}
288288
pdate := func(p1, p2 *Page) bool {
289-
return p1.GetParam(key).(time.Time).Unix() < p2.GetParam(key).(time.Time).Unix()
289+
return p1.getParamToLower(key).(time.Time).Unix() < p2.getParamToLower(key).(time.Time).Unix()
290290
}
291291
pageBy(pdate).Sort(r)
292292
return r
293293
}
294294
formatter := func(p *Page) string {
295-
return p.GetParam(key).(time.Time).Format(format)
295+
return p.getParamToLower(key).(time.Time).Format(format)
296296
}
297297
return p.groupByDateField(sorter, formatter, order...)
298298
}

hugolib/page_taxonomy_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestParseTaxonomies(t *testing.T) {
7272
t.Fatalf("Failed parsing %q: %s", test, err)
7373
}
7474

75-
param := p.GetParam("tags")
75+
param := p.getParamToLower("tags")
7676

7777
if params, ok := param.([]string); ok {
7878
expected := []string{"a", "b", "c"}
@@ -86,7 +86,7 @@ func TestParseTaxonomies(t *testing.T) {
8686
}
8787
}
8888

89-
param = p.GetParam("categories")
89+
param = p.getParamToLower("categories")
9090
singleparam := param.(string)
9191

9292
if singleparam != "d" {

hugolib/page_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -1067,22 +1067,22 @@ func TestDifferentFrontMatterVarTypes(t *testing.T) {
10671067
_, _ = page.ReadFrom(strings.NewReader(pageWithVariousFrontmatterTypes))
10681068

10691069
dateval, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z")
1070-
if page.GetParam("a_string") != "bar" {
1071-
t.Errorf("frontmatter not handling strings correctly should be %s, got: %s", "bar", page.GetParam("a_string"))
1070+
if page.getParamToLower("a_string") != "bar" {
1071+
t.Errorf("frontmatter not handling strings correctly should be %s, got: %s", "bar", page.getParamToLower("a_string"))
10721072
}
1073-
if page.GetParam("an_integer") != 1 {
1074-
t.Errorf("frontmatter not handling ints correctly should be %s, got: %s", "1", page.GetParam("an_integer"))
1073+
if page.getParamToLower("an_integer") != 1 {
1074+
t.Errorf("frontmatter not handling ints correctly should be %s, got: %s", "1", page.getParamToLower("an_integer"))
10751075
}
1076-
if page.GetParam("a_float") != 1.3 {
1077-
t.Errorf("frontmatter not handling floats correctly should be %f, got: %s", 1.3, page.GetParam("a_float"))
1076+
if page.getParamToLower("a_float") != 1.3 {
1077+
t.Errorf("frontmatter not handling floats correctly should be %f, got: %s", 1.3, page.getParamToLower("a_float"))
10781078
}
1079-
if page.GetParam("a_bool") != false {
1080-
t.Errorf("frontmatter not handling bools correctly should be %t, got: %s", false, page.GetParam("a_bool"))
1079+
if page.getParamToLower("a_bool") != false {
1080+
t.Errorf("frontmatter not handling bools correctly should be %t, got: %s", false, page.getParamToLower("a_bool"))
10811081
}
1082-
if page.GetParam("a_date") != dateval {
1083-
t.Errorf("frontmatter not handling dates correctly should be %s, got: %s", dateval, page.GetParam("a_date"))
1082+
if page.getParamToLower("a_date") != dateval {
1083+
t.Errorf("frontmatter not handling dates correctly should be %s, got: %s", dateval, page.getParamToLower("a_date"))
10841084
}
1085-
param := page.GetParam("a_table")
1085+
param := page.getParamToLower("a_table")
10861086
if param == nil {
10871087
t.Errorf("frontmatter not handling tables correctly should be type of %v, got: type of %v", reflect.TypeOf(page.Params["a_table"]), reflect.TypeOf(param))
10881088
}

hugolib/site.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ func (s *Site) assembleTaxonomies() {
14511451

14521452
for _, p := range s.Pages {
14531453
vals := p.getParam(plural, !s.Info.preserveTaxonomyNames)
1454-
weight := p.GetParam(plural + "_weight")
1454+
weight := p.getParamToLower(plural + "_weight")
14551455
if weight == nil {
14561456
weight = 0
14571457
}

0 commit comments

Comments
 (0)