shithub: hugo

Download patch

ref: 1c114d539b0755724443fe28c90b12fe2a19085a
parent: e14129461983204cab6105a31fd83834254bd3d9
author: Bjørn Erik Pedersen <[email protected]>
date: Fri Dec 29 03:58:38 EST 2017

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

--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -714,7 +714,7 @@
 
 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) GetParam(key string) interface{} {
+	return p.getParam(key, false)
+}
+
+func (p *Page) getParamToLower(key string) interface{} {
 	return p.getParam(key, true)
 }
 
--- a/hugolib/pageGroup.go
+++ b/hugolib/pageGroup.go
@@ -167,7 +167,7 @@
 	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 @@
 	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 @@
 			}
 		}
 		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...)
 }
--- a/hugolib/page_taxonomy_test.go
+++ b/hugolib/page_taxonomy_test.go
@@ -72,7 +72,7 @@
 			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 @@
 			}
 		}
 
-		param = p.GetParam("categories")
+		param = p.getParamToLower("categories")
 		singleparam := param.(string)
 
 		if singleparam != "d" {
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -1067,22 +1067,22 @@
 	_, _ = 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))
 	}
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -1451,7 +1451,7 @@
 
 		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
 			}