ref: 322c567220aa4123a5d707629c1bebd375599912
parent: 91bb774ae4e129f7ed0624754b31479c960ef774
author: Vas Sudanagunta <[email protected]>
date: Thu Jan 25 18:03:55 EST 2018
Fix "date" page param Add test coverage for all date type page params that shadow date type page variables. Fixes #4323
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -1343,7 +1343,6 @@
if p.Date.IsZero() && p.s.Cfg.GetBool("useModTimeAsFallback") {
p.Date = p.Source.FileInfo().ModTime()
- p.params["date"] = p.Date
}
if p.Lastmod.IsZero() {
@@ -1354,6 +1353,8 @@
}
}
+
+ p.params["date"] = p.Date
p.params["lastmod"] = p.Lastmod
p.params["publishdate"] = p.PublishDate
p.params["expirydate"] = p.ExpiryDate
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -1033,7 +1033,7 @@
{emptyFM, "test.md", false, o, o, o, x, x}, // 3 year-one dates, 2 empty dates
{zero_FM, "test.md", false, o, o, o, x, x},
{emptyFM, "testy.md", true, s, o, s, x, x}, // 2 filesys, 1 year-one, 2 empty
- {zero_FM, "testy.md", true, s, o, s, x, x}, // Issue #4320
+ {zero_FM, "testy.md", true, s, o, s, x, x},
}
for i, test := range tests {
@@ -1052,13 +1052,17 @@
p := s.newPageFromFile(newFileInfo(sp, "", test.filename, fi, bundleNot))
p.ReadFrom(file)
- modified := cast.ToTime(p.params["modified"])
-
+ // check Page Variables
checkDate(t, i+1, "Date", p.Date, test.expDate, fi)
checkDate(t, i+1, "PubDate", p.PublishDate, test.expPub, fi)
checkDate(t, i+1, "LastMod", p.Lastmod, test.expLast, fi)
- checkDate(t, i+1, "LastMod", modified, test.expMod, fi)
checkDate(t, i+1, "LastMod", p.ExpiryDate, test.expExp, fi)
+
+ // check Page Params
+ checkDate(t, i+1, "param date", cast.ToTime(p.params["date"]), test.expDate, fi)
+ checkDate(t, i+1, "param publishdate", cast.ToTime(p.params["publishdate"]), test.expPub, fi)
+ checkDate(t, i+1, "param modified", cast.ToTime(p.params["modified"]), test.expMod, fi)
+ checkDate(t, i+1, "param expirydate", cast.ToTime(p.params["expirydate"]), test.expExp, fi)
}
}