hugolib: Allow arrays of arrays in frontmatter Params

Fixes #2752
This commit is contained in:
Cameron Moore 2016-12-27 20:08:24 -06:00 committed by Bjørn Erik Pedersen
parent 3286b24fce
commit 3d058a936f
2 changed files with 57 additions and 0 deletions

View file

@ -1018,6 +1018,8 @@ func (p *Page) update(f interface{}) error {
p.Params[loki] = vvv
case map[string]interface{}: // Proper parsing structured array from JSON based FrontMatter
p.Params[loki] = vvv
case []interface{}:
p.Params[loki] = vvv
default:
a := make([]string, len(vvv))
for i, u := range vvv {

View file

@ -1261,6 +1261,61 @@ func TestDraft(t *testing.T) {
}
}
var pagesParamsTemplate = []string{`+++
title = "okay"
draft = false
tags = [ "hugo", "web" ]
social= [
[ "a", "#" ],
[ "b", "#" ],
]
+++
some content
`,
`---
title: "okay"
draft: false
tags:
- hugo
- web
social:
- - a
- "#"
- - b
- "#"
---
some content
`,
`{
"title": "okay",
"draft": false,
"tags": [ "hugo", "web" ],
"social": [
[ "a", "#" ],
[ "b", "#" ]
]
}
some content
`,
}
func TestPageParams(t *testing.T) {
want := map[string]interface{}{
"tags": []string{"hugo", "web"},
// Issue #2752
"social": []interface{}{
[]interface{}{"a", "#"},
[]interface{}{"b", "#"},
},
}
for i, c := range pagesParamsTemplate {
p, err := NewPageFrom(strings.NewReader(c), "content/post/params.md")
require.NoError(t, err, "err during parse", "#%d", i)
assert.Equal(t, want, p.Params, "#%d", i)
}
}
func TestPageSimpleMethods(t *testing.T) {
for i, this := range []struct {
assertFunc func(p *Page) bool