ref: 3d058a936ffef189c65686a74be1b4036594a3cc
parent: 3286b24fce03b8302c17939cbbabcb0e0e9b0eb7
author: Cameron Moore <[email protected]>
date: Tue Dec 27 15:08:24 EST 2016
hugolib: Allow arrays of arrays in frontmatter Params Fixes #2752
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -1018,6 +1018,8 @@
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 {
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -1261,6 +1261,61 @@
}
}
+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