Fix Params case handling in the new site global

Fixes #5615
This commit is contained in:
Bjørn Erik Pedersen 2019-01-18 17:48:19 +00:00
parent db3c49d049
commit e1a66c7343
3 changed files with 25 additions and 1 deletions

View file

@ -125,6 +125,7 @@ Shortcode Site: {{ .Page.Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
writeToFs(t, fs, "layouts/partials/partial.html", ` writeToFs(t, fs, "layouts/partials/partial.html", `
Partial Page: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }} Partial Page: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }}
Partial Site: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }} Partial Site: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
Partial Site Global: {{ site.Params.COLOR }}|{{ site.Params.COLORS.YELLOW }}
`) `)
writeToFs(t, fs, "config.toml", caseMixingSiteConfigTOML) writeToFs(t, fs, "config.toml", caseMixingSiteConfigTOML)
@ -200,6 +201,7 @@ Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
"Shortcode Site: green|yellow", "Shortcode Site: green|yellow",
"Partial Page: red|heavenly", "Partial Page: red|heavenly",
"Partial Site: green|yellow", "Partial Site: green|yellow",
"Partial Site Global: green|yellow",
"Page Title: Side 1", "Page Title: Side 1",
"Site Title: Nynorsk title", "Site Title: Nynorsk title",
"«Hi»", // angled quotes "«Hi»", // angled quotes

View file

@ -130,8 +130,12 @@ func (c *templateContext) paramsKeysToLower(n parse.Node) {
c.updateIdentsIfNeeded(an.Ident) c.updateIdentsIfNeeded(an.Ident)
case *parse.PipeNode: case *parse.PipeNode:
c.paramsKeysToLower(an) c.paramsKeysToLower(an)
case *parse.ChainNode:
// site.Params...
if len(an.Field) > 1 && an.Field[0] == paramsIdentifier {
c.updateIdentsIfNeeded(an.Field)
}
} }
} }
} }
} }

View file

@ -34,6 +34,13 @@ var (
"ByWeight": fmt.Sprintf("%v:%v:%v", seq, key, args), "ByWeight": fmt.Sprintf("%v:%v:%v", seq, key, args),
}, nil }, nil
}, },
"site": func() interface{} {
return map[string]interface{}{
"Params": map[string]interface{}{
"lower": "global-site",
},
}
},
} }
paramsData = map[string]interface{}{ paramsData = map[string]interface{}{
@ -154,6 +161,12 @@ PARAMS TIME: {{ $time.Format "2006-01-02" }}
{{ $_x := $.Params.MyDate | ToTime }} {{ $_x := $.Params.MyDate | ToTime }}
PARAMS TIME2: {{ $_x.AddDate 0 1 0 }} PARAMS TIME2: {{ $_x.AddDate 0 1 0 }}
PARAMS SITE GLOBAL1: {{ site.Params.LOwER }}
{{ $lower := site.Params.LOwER }}
{{ $site := site }}
PARAMS SITE GLOBAL2: {{ $lower }}
PARAMS SITE GLOBAL3: {{ $site.Params.LOWER }}
` `
) )
@ -225,6 +238,11 @@ func TestParamsKeysToLower(t *testing.T) {
require.Contains(t, result, "PARAMS TIME: 1972-02-28") require.Contains(t, result, "PARAMS TIME: 1972-02-28")
require.Contains(t, result, "PARAMS TIME2: 1972-02-28") require.Contains(t, result, "PARAMS TIME2: 1972-02-28")
// Issue ##5615
require.Contains(t, result, "PARAMS SITE GLOBAL1: global-site")
require.Contains(t, result, "PARAMS SITE GLOBAL2: global-site")
require.Contains(t, result, "PARAMS SITE GLOBAL3: global-site")
} }
func BenchmarkTemplateParamsKeysToLower(b *testing.B) { func BenchmarkTemplateParamsKeysToLower(b *testing.B) {