Fix "date" page param

Add test coverage for all date type page params that shadow date type page variables.

Fixes #4323
This commit is contained in:
Vas Sudanagunta 2018-01-25 23:03:55 -05:00 committed by Bjørn Erik Pedersen
parent 91bb774ae4
commit 322c567220
2 changed files with 10 additions and 5 deletions

View file

@ -1343,7 +1343,6 @@ func (p *Page) update(frontmatter map[string]interface{}) error {
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 @@ func (p *Page) update(frontmatter map[string]interface{}) error {
}
}
p.params["date"] = p.Date
p.params["lastmod"] = p.Lastmod
p.params["publishdate"] = p.PublishDate
p.params["expirydate"] = p.ExpiryDate

View file

@ -1033,7 +1033,7 @@ func TestMetadataDates(t *testing.T) {
{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 @@ func TestMetadataDates(t *testing.T) {
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)
}
}