shithub: hugo

Download patch

ref: 69c1944f1fa78502aa3bd19ff59b2a96c8c7a6c4
parent: 4a8de8ea46f45776518c7086222be0c94c893764
author: spf13 <[email protected]>
date: Tue Apr 22 22:55:43 EDT 2014

Add handling of deeply nested front matter

--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -247,6 +247,7 @@
 
 	if override, ok := p.Site.Permalinks[p.Section]; ok {
 		permalink, err = override.Expand(p)
+
 		if err != nil {
 			return nil, err
 		}
@@ -384,6 +385,8 @@
 						a[i] = cast.ToString(u)
 					}
 					page.Params[loki] = a
+				default:
+					page.Params[loki] = vv
 				}
 			}
 		}
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -24,6 +24,7 @@
 	"time"
 
 	"bitbucket.org/pkg/inflect"
+	"github.com/spf13/cast"
 	"github.com/spf13/hugo/helpers"
 	"github.com/spf13/hugo/source"
 	"github.com/spf13/hugo/target"
@@ -60,7 +61,7 @@
 	Taxonomies TaxonomyList
 	Source     source.Input
 	Sections   Taxonomy
-	Info       SiteInfo
+	Info       *SiteInfo
 	Shortcodes map[string]ShortcodeFunc
 	timer      *nitro.B
 	Target     target.Output
@@ -85,6 +86,29 @@
 	Permalinks      PermalinkOverrides
 	Params          map[string]interface{}
 }
+
+func (s *SiteInfo) GetParam(key string) interface{} {
+	v := s.Params[strings.ToLower(key)]
+
+	if v == nil {
+		return nil
+	}
+
+	switch v.(type) {
+	case bool:
+		return cast.ToBool(v)
+	case string:
+		return cast.ToString(v)
+	case int64, int32, int16, int8, int:
+		return cast.ToInt(v)
+	case float64, float32:
+		return cast.ToFloat64(v)
+	case time.Time:
+		return cast.ToTime(v)
+	case []string:
+		return v
+	}
+	return nil
 }
 
 type runmode struct {
@@ -292,7 +316,7 @@
 			if err != nil {
 				return err
 			}
-			page.Site = s.Info
+			page.Site = *s.Info
 			page.Tmpl = s.Tmpl
 			page.Section = file.Section
 			page.Dir = file.Dir
@@ -648,7 +672,7 @@
 func (s *Site) NewNode() *Node {
 	return &Node{
 		Data: make(map[string]interface{}),
-		Site: s.Info,
+		Site: *s.Info,
 	}
 }