diff options
author | bep <bjorn.erik.pedersen@gmail.com> | 2015-01-05 14:44:41 +0300 |
---|---|---|
committer | bep <bjorn.erik.pedersen@gmail.com> | 2015-01-05 14:44:41 +0300 |
commit | 837922d32bc1d0d2fbc50af07947e6b858df1550 (patch) | |
tree | f4820edf0ce1c389bd18446b8a53e11ce34c3d12 /hugolib/page.go | |
parent | 0d17ee7ed4331513adb6e08f5697c4d803155655 (diff) |
Add ERROR logging on invalid date and publishdate
Having correct dates is important in Hugo. Previously date parsing errors were swallowed, leading to confusing results.
This commit adds ERROR logging when date or publishdate in front matter cannot be parsed into a time.Time.
Diffstat (limited to 'hugolib/page.go')
-rw-r--r-- | hugolib/page.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/hugolib/page.go b/hugolib/page.go index 7c189ca28..2ebc17b6b 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -397,7 +397,7 @@ func (page *Page) update(f interface{}) error { return fmt.Errorf("no metadata found") } m := f.(map[string]interface{}) - + var err error for k, v := range m { loki := strings.ToLower(k) switch loki { @@ -421,9 +421,15 @@ func (page *Page) update(f interface{}) error { case "keywords": page.Keywords = cast.ToStringSlice(v) case "date": - page.Date = cast.ToTime(v) + page.Date, err = cast.ToTimeE(v) + if err != nil { + jww.ERROR.Printf("Failed to parse date '%v' in page %s", v, page.File.Path()) + } case "publishdate", "pubdate": - page.PublishDate = cast.ToTime(v) + page.PublishDate, err = cast.ToTimeE(v) + if err != nil { + jww.ERROR.Printf("Failed to parse publishdate '%v' in page %s", v, page.File.Path()) + } case "draft": page.Draft = cast.ToBool(v) case "layout": |