Proper parsing structured array from yaml based FrontMatter
authorPiotr Kowalczuk <p.kowalczuk.priv@gmail.com>
Thu, 25 Jun 2015 09:46:09 +0000 (11:46 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 25 Jun 2015 15:56:22 +0000 (17:56 +0200)
hugolib/page.go

index 19408eee57b30b0f405ec6a3c9e75b86c4c89e1d..385bf8736d2577858a37d10249c86da9c19ecf44 100644 (file)
@@ -518,11 +518,21 @@ func (p *Page) update(f interface{}) error {
                        default: // handle array of strings as well
                                switch vvv := vv.(type) {
                                case []interface{}:
-                                       var a = make([]string, len(vvv))
-                                       for i, u := range vvv {
-                                               a[i] = cast.ToString(u)
+                                       if len(vvv) > 0 {
+                                               switch vvv[0].(type) {
+                                               case map[interface{}]interface{}: // Proper parsing structured array from yaml based FrontMatter
+                                                       p.Params[loki] = vvv
+                                               default:
+                                                       a := make([]string, len(vvv))
+                                                       for i, u := range vvv {
+                                                               a[i] = cast.ToString(u)
+                                                       }
+
+                                                       p.Params[loki] = a
+                                               }
+                                       } else {
+                                               p.Params[loki] = []string{}
                                        }
-                                       p.Params[loki] = a
                                default:
                                        p.Params[loki] = vv
                                }