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
This commit is contained in:
Bjørn Erik Pedersen 2017-12-29 08:58:38 +01:00
parent e141294619
commit 1c114d539b
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
5 changed files with 23 additions and 19 deletions

View file

@ -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)
}

View file

@ -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...)
}

View file

@ -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" {

View file

@ -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))
}

View file

@ -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
}