From 69c1944f1fa78502aa3bd19ff59b2a96c8c7a6c4 Mon Sep 17 00:00:00 2001 From: spf13 Date: Wed, 23 Apr 2014 02:55:43 -0400 Subject: [PATCH] Add handling of deeply nested front matter --- hugolib/page.go | 3 +++ hugolib/site.go | 30 +++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/hugolib/page.go b/hugolib/page.go index 206652334..ec5d2f0af 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -247,6 +247,7 @@ func (p *Page) permalink() (*url.URL, error) { if override, ok := p.Site.Permalinks[p.Section]; ok { permalink, err = override.Expand(p) + if err != nil { return nil, err } @@ -384,6 +385,8 @@ func (page *Page) update(f interface{}) error { a[i] = cast.ToString(u) } page.Params[loki] = a + default: + page.Params[loki] = vv } } } diff --git a/hugolib/site.go b/hugolib/site.go index 20d03cb01..bc5d64a8a 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -24,6 +24,7 @@ import ( "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 @@ type Site struct { 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 @@ type SiteInfo struct { 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 @@ func (s *Site) CreatePages() (err error) { 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) PrettifyPath(in string) string { func (s *Site) NewNode() *Node { return &Node{ Data: make(map[string]interface{}), - Site: s.Info, + Site: *s.Info, } }