mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	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:
		@@ -714,7 +714,7 @@ func (p *Page) renderContent(content []byte) []byte {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (p *Page) getRenderingConfig() *helpers.BlackFriday {
 | 
					func (p *Page) getRenderingConfig() *helpers.BlackFriday {
 | 
				
			||||||
	p.renderingConfigInit.Do(func() {
 | 
						p.renderingConfigInit.Do(func() {
 | 
				
			||||||
		bfParam := p.GetParam("blackfriday")
 | 
							bfParam := p.getParamToLower("blackfriday")
 | 
				
			||||||
		if bfParam == nil {
 | 
							if bfParam == nil {
 | 
				
			||||||
			p.renderingConfig = p.s.ContentSpec.BlackFriday
 | 
								p.renderingConfig = p.s.ContentSpec.BlackFriday
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
@@ -1306,6 +1306,10 @@ func (p *Page) update(f interface{}) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (p *Page) GetParam(key string) interface{} {
 | 
					func (p *Page) GetParam(key string) interface{} {
 | 
				
			||||||
 | 
						return p.getParam(key, false)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (p *Page) getParamToLower(key string) interface{} {
 | 
				
			||||||
	return p.getParam(key, true)
 | 
						return p.getParam(key, true)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -167,7 +167,7 @@ func (p Pages) GroupByParam(key string, order ...string) (PagesGroup, error) {
 | 
				
			|||||||
	var tmp reflect.Value
 | 
						var tmp reflect.Value
 | 
				
			||||||
	var keyt reflect.Type
 | 
						var keyt reflect.Type
 | 
				
			||||||
	for _, e := range p {
 | 
						for _, e := range p {
 | 
				
			||||||
		param := e.GetParam(key)
 | 
							param := e.getParamToLower(key)
 | 
				
			||||||
		if param != nil {
 | 
							if param != nil {
 | 
				
			||||||
			if _, ok := param.([]string); !ok {
 | 
								if _, ok := param.([]string); !ok {
 | 
				
			||||||
				keyt = reflect.TypeOf(param)
 | 
									keyt = reflect.TypeOf(param)
 | 
				
			||||||
@@ -278,7 +278,7 @@ func (p Pages) GroupByParamDate(key string, format string, order ...string) (Pag
 | 
				
			|||||||
	sorter := func(p Pages) Pages {
 | 
						sorter := func(p Pages) Pages {
 | 
				
			||||||
		var r Pages
 | 
							var r Pages
 | 
				
			||||||
		for _, e := range p {
 | 
							for _, e := range p {
 | 
				
			||||||
			param := e.GetParam(key)
 | 
								param := e.getParamToLower(key)
 | 
				
			||||||
			if param != nil {
 | 
								if param != nil {
 | 
				
			||||||
				if _, ok := param.(time.Time); ok {
 | 
									if _, ok := param.(time.Time); ok {
 | 
				
			||||||
					r = append(r, e)
 | 
										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 {
 | 
							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)
 | 
							pageBy(pdate).Sort(r)
 | 
				
			||||||
		return r
 | 
							return r
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	formatter := func(p *Page) string {
 | 
						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...)
 | 
						return p.groupByDateField(sorter, formatter, order...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,7 +72,7 @@ func TestParseTaxonomies(t *testing.T) {
 | 
				
			|||||||
			t.Fatalf("Failed parsing %q: %s", test, err)
 | 
								t.Fatalf("Failed parsing %q: %s", test, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		param := p.GetParam("tags")
 | 
							param := p.getParamToLower("tags")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if params, ok := param.([]string); ok {
 | 
							if params, ok := param.([]string); ok {
 | 
				
			||||||
			expected := []string{"a", "b", "c"}
 | 
								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)
 | 
							singleparam := param.(string)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if singleparam != "d" {
 | 
							if singleparam != "d" {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1067,22 +1067,22 @@ func TestDifferentFrontMatterVarTypes(t *testing.T) {
 | 
				
			|||||||
	_, _ = page.ReadFrom(strings.NewReader(pageWithVariousFrontmatterTypes))
 | 
						_, _ = page.ReadFrom(strings.NewReader(pageWithVariousFrontmatterTypes))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dateval, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z")
 | 
						dateval, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z")
 | 
				
			||||||
	if page.GetParam("a_string") != "bar" {
 | 
						if page.getParamToLower("a_string") != "bar" {
 | 
				
			||||||
		t.Errorf("frontmatter not handling strings correctly should be %s, got: %s", "bar", page.GetParam("a_string"))
 | 
							t.Errorf("frontmatter not handling strings correctly should be %s, got: %s", "bar", page.getParamToLower("a_string"))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if page.GetParam("an_integer") != 1 {
 | 
						if page.getParamToLower("an_integer") != 1 {
 | 
				
			||||||
		t.Errorf("frontmatter not handling ints correctly should be %s, got: %s", "1", page.GetParam("an_integer"))
 | 
							t.Errorf("frontmatter not handling ints correctly should be %s, got: %s", "1", page.getParamToLower("an_integer"))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if page.GetParam("a_float") != 1.3 {
 | 
						if page.getParamToLower("a_float") != 1.3 {
 | 
				
			||||||
		t.Errorf("frontmatter not handling floats correctly should be %f, got: %s", 1.3, page.GetParam("a_float"))
 | 
							t.Errorf("frontmatter not handling floats correctly should be %f, got: %s", 1.3, page.getParamToLower("a_float"))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if page.GetParam("a_bool") != false {
 | 
						if page.getParamToLower("a_bool") != false {
 | 
				
			||||||
		t.Errorf("frontmatter not handling bools correctly should be %t, got: %s", false, page.GetParam("a_bool"))
 | 
							t.Errorf("frontmatter not handling bools correctly should be %t, got: %s", false, page.getParamToLower("a_bool"))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if page.GetParam("a_date") != dateval {
 | 
						if page.getParamToLower("a_date") != dateval {
 | 
				
			||||||
		t.Errorf("frontmatter not handling dates correctly should be %s, got: %s", dateval, page.GetParam("a_date"))
 | 
							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 {
 | 
						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))
 | 
							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))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1451,7 +1451,7 @@ func (s *Site) assembleTaxonomies() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		for _, p := range s.Pages {
 | 
							for _, p := range s.Pages {
 | 
				
			||||||
			vals := p.getParam(plural, !s.Info.preserveTaxonomyNames)
 | 
								vals := p.getParam(plural, !s.Info.preserveTaxonomyNames)
 | 
				
			||||||
			weight := p.GetParam(plural + "_weight")
 | 
								weight := p.getParamToLower(plural + "_weight")
 | 
				
			||||||
			if weight == nil {
 | 
								if weight == nil {
 | 
				
			||||||
				weight = 0
 | 
									weight = 0
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user