From 1c114d539b0755724443fe28c90b12fe2a19085a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 29 Dec 2017 08:58:38 +0100 Subject: 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 --- hugolib/page.go | 6 +++++- hugolib/pageGroup.go | 8 ++++---- hugolib/page_taxonomy_test.go | 4 ++-- hugolib/page_test.go | 22 +++++++++++----------- hugolib/site.go | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) (limited to 'hugolib') diff --git a/hugolib/page.go b/hugolib/page.go index d589ffcc1..a10887ad4 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -714,7 +714,7 @@ func (p *Page) renderContent(content []byte) []byte { func (p *Page) getRenderingConfig() *helpers.BlackFriday { p.renderingConfigInit.Do(func() { - bfParam := p.GetParam("blackfriday") + bfParam := p.getParamToLower("blackfriday") if bfParam == nil { p.renderingConfig = p.s.ContentSpec.BlackFriday return @@ -1306,6 +1306,10 @@ func (p *Page) update(f interface{}) error { } func (p *Page) GetParam(key string) interface{} { + return p.getParam(key, false) +} + +func (p *Page) getParamToLower(key string) interface{} { return p.getParam(key, true) } diff --git a/hugolib/pageGroup.go b/hugolib/pageGroup.go index 00b8e278a..8aaa1018c 100644 --- a/hugolib/pageGroup.go +++ b/hugolib/pageGroup.go @@ -167,7 +167,7 @@ func (p Pages) GroupByParam(key string, order ...string) (PagesGroup, error) { var tmp reflect.Value var keyt reflect.Type for _, e := range p { - param := e.GetParam(key) + param := e.getParamToLower(key) if param != nil { if _, ok := param.([]string); !ok { keyt = reflect.TypeOf(param) @@ -278,7 +278,7 @@ func (p Pages) GroupByParamDate(key string, format string, order ...string) (Pag sorter := func(p Pages) Pages { var r Pages for _, e := range p { - param := e.GetParam(key) + param := e.getParamToLower(key) if param != nil { if _, ok := param.(time.Time); ok { r = append(r, e) @@ -286,13 +286,13 @@ func (p Pages) GroupByParamDate(key string, format string, order ...string) (Pag } } pdate := func(p1, p2 *Page) bool { - return p1.GetParam(key).(time.Time).Unix() < p2.GetParam(key).(time.Time).Unix() + return p1.getParamToLower(key).(time.Time).Unix() < p2.getParamToLower(key).(time.Time).Unix() } pageBy(pdate).Sort(r) return r } formatter := func(p *Page) string { - return p.GetParam(key).(time.Time).Format(format) + return p.getParamToLower(key).(time.Time).Format(format) } return p.groupByDateField(sorter, formatter, order...) } diff --git a/hugolib/page_taxonomy_test.go b/hugolib/page_taxonomy_test.go index e0dc1ffbc..ed1d2565d 100644 --- a/hugolib/page_taxonomy_test.go +++ b/hugolib/page_taxonomy_test.go @@ -72,7 +72,7 @@ func TestParseTaxonomies(t *testing.T) { t.Fatalf("Failed parsing %q: %s", test, err) } - param := p.GetParam("tags") + param := p.getParamToLower("tags") if params, ok := param.([]string); ok { expected := []string{"a", "b", "c"} @@ -86,7 +86,7 @@ func TestParseTaxonomies(t *testing.T) { } } - param = p.GetParam("categories") + param = p.getParamToLower("categories") singleparam := param.(string) if singleparam != "d" { diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 7b6dd646a..769d29833 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -1067,22 +1067,22 @@ func TestDifferentFrontMatterVarTypes(t *testing.T) { _, _ = page.ReadFrom(strings.NewReader(pageWithVariousFrontmatterTypes)) dateval, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z") - if page.GetParam("a_string") != "bar" { - t.Errorf("frontmatter not handling strings correctly should be %s, got: %s", "bar", page.GetParam("a_string")) + if page.getParamToLower("a_string") != "bar" { + t.Errorf("frontmatter not handling strings correctly should be %s, got: %s", "bar", page.getParamToLower("a_string")) } - if page.GetParam("an_integer") != 1 { - t.Errorf("frontmatter not handling ints correctly should be %s, got: %s", "1", page.GetParam("an_integer")) + if page.getParamToLower("an_integer") != 1 { + t.Errorf("frontmatter not handling ints correctly should be %s, got: %s", "1", page.getParamToLower("an_integer")) } - if page.GetParam("a_float") != 1.3 { - t.Errorf("frontmatter not handling floats correctly should be %f, got: %s", 1.3, page.GetParam("a_float")) + if page.getParamToLower("a_float") != 1.3 { + t.Errorf("frontmatter not handling floats correctly should be %f, got: %s", 1.3, page.getParamToLower("a_float")) } - if page.GetParam("a_bool") != false { - t.Errorf("frontmatter not handling bools correctly should be %t, got: %s", false, page.GetParam("a_bool")) + if page.getParamToLower("a_bool") != false { + t.Errorf("frontmatter not handling bools correctly should be %t, got: %s", false, page.getParamToLower("a_bool")) } - if page.GetParam("a_date") != dateval { - t.Errorf("frontmatter not handling dates correctly should be %s, got: %s", dateval, page.GetParam("a_date")) + if page.getParamToLower("a_date") != dateval { + t.Errorf("frontmatter not handling dates correctly should be %s, got: %s", dateval, page.getParamToLower("a_date")) } - param := page.GetParam("a_table") + param := page.getParamToLower("a_table") if param == nil { 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)) } diff --git a/hugolib/site.go b/hugolib/site.go index a5e2144e1..71a4083ef 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -1451,7 +1451,7 @@ func (s *Site) assembleTaxonomies() { for _, p := range s.Pages { vals := p.getParam(plural, !s.Info.preserveTaxonomyNames) - weight := p.GetParam(plural + "_weight") + weight := p.getParamToLower(plural + "_weight") if weight == nil { weight = 0 } -- cgit v1.2.3