Skip to content

Commit 202510f

Browse files
committed
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
1 parent 573deca commit 202510f

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

‎hugolib/page.go‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,8 @@ func (p *Page) update(f interface{}) error {
971971
// Needed for case insensitive fetching of params values
972972
helpers.ToLowerMap(m)
973973

974+
var modified time.Time
975+
974976
var err error
975977
var draft, published, isCJKLanguage *bool
976978
for k, v := range m {
@@ -1014,6 +1016,14 @@ func (p *Page) update(f interface{}) error {
10141016
if err != nil {
10151017
p.s.Log.ERROR.Printf("Failed to parse lastmod '%v' in page %s", v, p.File.Path())
10161018
}
1019+
case "modified":
1020+
vv, err := cast.ToTimeE(v)
1021+
if err == nil {
1022+
p.Params[loki] = vv
1023+
modified = vv
1024+
} else {
1025+
p.Params[loki] = cast.ToString(v)
1026+
}
10171027
case "outputs":
10181028
o := cast.ToStringSlice(v)
10191029
if len(o) > 0 {
@@ -1034,6 +1044,7 @@ func (p *Page) update(f interface{}) error {
10341044
if err != nil {
10351045
p.s.Log.ERROR.Printf("Failed to parse publishdate '%v' in page %s", v, p.File.Path())
10361046
}
1047+
p.Params[loki] = p.PublishDate
10371048
case "expirydate", "unpublishdate":
10381049
p.ExpiryDate, err = cast.ToTimeE(v)
10391050
if err != nil {
@@ -1043,8 +1054,19 @@ func (p *Page) update(f interface{}) error {
10431054
draft = new(bool)
10441055
*draft = cast.ToBool(v)
10451056
case "published": // Intentionally undocumented
1046-
published = new(bool)
1047-
*published = cast.ToBool(v)
1057+
vv, err := cast.ToBoolE(v)
1058+
if err == nil {
1059+
published = &vv
1060+
} else {
1061+
// Some sites use this as the publishdate
1062+
vv, err := cast.ToTimeE(v)
1063+
if err == nil {
1064+
p.PublishDate = vv
1065+
p.Params[loki] = p.PublishDate
1066+
} else {
1067+
p.Params[loki] = cast.ToString(v)
1068+
}
1069+
}
10481070
case "layout":
10491071
p.Layout = cast.ToString(v)
10501072
p.Params[loki] = p.Layout
@@ -1133,9 +1155,16 @@ func (p *Page) update(f interface{}) error {
11331155
}
11341156

11351157
if p.Lastmod.IsZero() {
1136-
p.Lastmod = p.Date
1158+
if !modified.IsZero() {
1159+
p.Lastmod = modified
1160+
} else {
1161+
p.Lastmod = p.Date
1162+
}
1163+
11371164
}
11381165
p.Params["lastmod"] = p.Lastmod
1166+
p.Params["publishdate"] = p.PublishDate
1167+
p.Params["expirydate"] = p.ExpiryDate
11391168

11401169
if isCJKLanguage != nil {
11411170
p.isCJKLanguage = *isCJKLanguage

0 commit comments

Comments
 (0)