mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 08:42:08 -05:00
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:
parent
91bb774ae4
commit
322c567220
2 changed files with 10 additions and 5 deletions
|
@ -1343,7 +1343,6 @@ func (p *Page) update(frontmatter map[string]interface{}) error {
|
||||||
|
|
||||||
if p.Date.IsZero() && p.s.Cfg.GetBool("useModTimeAsFallback") {
|
if p.Date.IsZero() && p.s.Cfg.GetBool("useModTimeAsFallback") {
|
||||||
p.Date = p.Source.FileInfo().ModTime()
|
p.Date = p.Source.FileInfo().ModTime()
|
||||||
p.params["date"] = p.Date
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Lastmod.IsZero() {
|
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["lastmod"] = p.Lastmod
|
||||||
p.params["publishdate"] = p.PublishDate
|
p.params["publishdate"] = p.PublishDate
|
||||||
p.params["expirydate"] = p.ExpiryDate
|
p.params["expirydate"] = p.ExpiryDate
|
||||||
|
|
|
@ -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
|
{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},
|
{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
|
{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 {
|
for i, test := range tests {
|
||||||
|
@ -1052,13 +1052,17 @@ func TestMetadataDates(t *testing.T) {
|
||||||
p := s.newPageFromFile(newFileInfo(sp, "", test.filename, fi, bundleNot))
|
p := s.newPageFromFile(newFileInfo(sp, "", test.filename, fi, bundleNot))
|
||||||
p.ReadFrom(file)
|
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, "Date", p.Date, test.expDate, fi)
|
||||||
checkDate(t, i+1, "PubDate", p.PublishDate, test.expPub, 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", p.Lastmod, test.expLast, fi)
|
||||||
checkDate(t, i+1, "LastMod", modified, test.expMod, fi)
|
|
||||||
checkDate(t, i+1, "LastMod", p.ExpiryDate, test.expExp, 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue