From 322c567220aa4123a5d707629c1bebd375599912 Mon Sep 17 00:00:00 2001 From: Vas Sudanagunta Date: Thu, 25 Jan 2018 23:03:55 -0500 Subject: [PATCH] Fix "date" page param Add test coverage for all date type page params that shadow date type page variables. Fixes #4323 --- hugolib/page.go | 3 ++- hugolib/page_test.go | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/hugolib/page.go b/hugolib/page.go index 468353ebc..b7afc5065 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -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 diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 033051498..5c8c46c9b 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -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) } }