diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-09-08 12:28:15 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-09-08 12:28:15 +0200 |
commit | 202510fdc92d52a20baeaa7edb1091f6882bd95f (patch) | |
tree | 9f9de1ce94fab68e3df39e822db0a8add9026e1e | |
parent | 573deca089485dd4230520ef4279c89b8a363cb2 (diff) |
hugolib: Fix "published" front matter handling
Also related:
* support "modified" as an optional way to signal "last modified"
* make sure all relevant page dates are also added to params
Fixes #3867
-rw-r--r-- | hugolib/page.go | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/hugolib/page.go b/hugolib/page.go index a723cabb2..d5c444ed6 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -971,6 +971,8 @@ func (p *Page) update(f interface{}) error { // Needed for case insensitive fetching of params values helpers.ToLowerMap(m) + var modified time.Time + var err error var draft, published, isCJKLanguage *bool for k, v := range m { @@ -1014,6 +1016,14 @@ func (p *Page) update(f interface{}) error { if err != nil { p.s.Log.ERROR.Printf("Failed to parse lastmod '%v' in page %s", v, p.File.Path()) } + case "modified": + vv, err := cast.ToTimeE(v) + if err == nil { + p.Params[loki] = vv + modified = vv + } else { + p.Params[loki] = cast.ToString(v) + } case "outputs": o := cast.ToStringSlice(v) if len(o) > 0 { @@ -1034,6 +1044,7 @@ func (p *Page) update(f interface{}) error { if err != nil { p.s.Log.ERROR.Printf("Failed to parse publishdate '%v' in page %s", v, p.File.Path()) } + p.Params[loki] = p.PublishDate case "expirydate", "unpublishdate": p.ExpiryDate, err = cast.ToTimeE(v) if err != nil { @@ -1043,8 +1054,19 @@ func (p *Page) update(f interface{}) error { draft = new(bool) *draft = cast.ToBool(v) case "published": // Intentionally undocumented - published = new(bool) - *published = cast.ToBool(v) + vv, err := cast.ToBoolE(v) + if err == nil { + published = &vv + } else { + // Some sites use this as the publishdate + vv, err := cast.ToTimeE(v) + if err == nil { + p.PublishDate = vv + p.Params[loki] = p.PublishDate + } else { + p.Params[loki] = cast.ToString(v) + } + } case "layout": p.Layout = cast.ToString(v) p.Params[loki] = p.Layout @@ -1133,9 +1155,16 @@ func (p *Page) update(f interface{}) error { } if p.Lastmod.IsZero() { - p.Lastmod = p.Date + if !modified.IsZero() { + p.Lastmod = modified + } else { + p.Lastmod = p.Date + } + } p.Params["lastmod"] = p.Lastmod + p.Params["publishdate"] = p.PublishDate + p.Params["expirydate"] = p.ExpiryDate if isCJKLanguage != nil { p.isCJKLanguage = *isCJKLanguage |