ref: cd07e6d57b158a76f812e8c4c9567dbc84f57939
parent: 628efd6e293d27984a3f5ba33522f8edd19d69d6
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Thu Nov 21 14:45:03 EST 2019
Fix GetPage Params case issue Fixes #5946
--- a/hugolib/case_insensitive_test.go
+++ b/hugolib/case_insensitive_test.go
@@ -179,6 +179,10 @@
Site Lang Mood: {{ .Site.Language.Params.MOoD }}
Page Colors: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }}
Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
+{{ $page2 := .Site.GetPage "/sect2/page2" }}
+{{ if $page2 }}
+Page2: {{ $page2.Params.ColoR }}
+{{ end }}
{{ .Content }}
{{ partial "partial.html" . }}
`)
@@ -207,6 +211,7 @@
"Page Title: Side 1",
"Site Title: Nynorsk title",
"«Hi»", // angled quotes
+ "Page2: black ",
)
th.assertFileContent(filepath.Join("public", "en", "sect1", "page1", "index.html"),
--- a/hugolib/testhelpers_test.go
+++ b/hugolib/testhelpers_test.go
@@ -743,7 +743,7 @@
content := readDestination(th, th.Fs, filename)
for _, match := range matches {
match = th.replaceDefaultContentLanguageValue(match)
- th.Assert(strings.Contains(content, match), qt.Equals, true)
+ th.Assert(strings.Contains(content, match), qt.Equals, true, qt.Commentf(content))
}
}
--- a/tpl/tplimpl/template_ast_transformers.go
+++ b/tpl/tplimpl/template_ast_transformers.go
@@ -508,8 +508,7 @@
}
if !d.isKeyword(replacement) {
- // This can not be .Site.Params etc.
- return nil, false
+ continue
}
replacement = strings.TrimPrefix(replacement, ".")
--- a/tpl/tplimpl/template_ast_transformers_test.go
+++ b/tpl/tplimpl/template_ast_transformers_test.go
@@ -26,6 +26,19 @@
qt "github.com/frankban/quicktest"
)
+type paramsHolder struct {
+ params map[string]interface{}
+ page *paramsHolder
+}
+
+func (p paramsHolder) Params() map[string]interface{} {
+ return p.params
+}
+
+func (p paramsHolder) GetPage(arg string) *paramsHolder {
+ return p.page
+}
+
var (
testFuncs = map[string]interface{}{
"getif": func(v interface{}) interface{} { return v },
@@ -37,16 +50,22 @@
"ByWeight": fmt.Sprintf("%v:%v:%v", seq, key, args),
}, nil
},
- "site": func() interface{} {
- return map[string]interface{}{
- "Params": map[string]interface{}{
+ "site": func() paramsHolder {
+ return paramsHolder{
+ params: map[string]interface{}{
"lower": "global-site",
},
+ page: ¶msHolder{
+ params: map[string]interface{}{
+ "lower": "page",
+ },
+ },
}
},
}
paramsData = map[string]interface{}{
+
"NotParam": "Hi There",
"Slice": []int{1, 3},
"Params": map[string]interface{}{
@@ -81,6 +100,16 @@
},
},
},
+ "Site2": paramsHolder{
+ params: map[string]interface{}{
+ "lower": "global-site",
+ },
+ page: ¶msHolder{
+ params: map[string]interface{}{
+ "lower": "page",
+ },
+ },
+ },
}
paramsTempl = `
@@ -170,6 +199,11 @@
{{ $site := site }}
PARAMS SITE GLOBAL2: {{ $lower }}
PARAMS SITE GLOBAL3: {{ $site.Params.LOWER }}
+
+{{ $p := $site.GetPage "foo" }}
+PARAMS GETPAGE: {{ $p.Params.LOWER }}
+{{ $p := .Site2.GetPage "foo" }}
+PARAMS GETPAGE2: {{ $p.Params.LOWER }}
`
)
@@ -247,6 +281,10 @@
c.Assert(result, qt.Contains, "PARAMS SITE GLOBAL1: global-site")
c.Assert(result, qt.Contains, "PARAMS SITE GLOBAL2: global-site")
c.Assert(result, qt.Contains, "PARAMS SITE GLOBAL3: global-site")
+
+ //
+ c.Assert(result, qt.Contains, "PARAMS GETPAGE: page")
+ c.Assert(result, qt.Contains, "PARAMS GETPAGE2: page")
}