Skip to content

Commit

Permalink
hugolib: Allow arrays of arrays in frontmatter Params
Browse files Browse the repository at this point in the history
Fixes #2752
  • Loading branch information
moorereason authored and bep committed Jan 6, 2017
1 parent 3286b24 commit 3d058a9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hugolib/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
55 changes: 55 additions & 0 deletions hugolib/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3d058a9

Please sign in to comment.