Skip to content

Commit

Permalink
Adjust pubdate
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Feb 26, 2018
1 parent 1a3c899 commit b6ccbc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions hugolib/page_frontmatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ func (f frontmatterHandler) handleDates(d frontMatterDescriptor) error {
d.dates.Date = d.dates.PublishDate
}

if d.dates.PublishDate.IsZero() {
d.dates.PublishDate = d.dates.Date
}

if d.dates.Lastmod.IsZero() {
d.dates.Lastmod = d.dates.Date
}

if d.dates.Date.IsZero() {
d.dates.Date = d.dates.Lastmod
}

f.setParamIfNotZero("date", d.params, d.dates.Date)
f.setParamIfNotZero("lastmod", d.params, d.dates.Lastmod)
f.setParamIfNotZero("publishdate", d.params, d.dates.PublishDate)
Expand Down
14 changes: 9 additions & 5 deletions hugolib/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ func TestPageWithDelimiterForMarkdownThatCrossesBorder(t *testing.T) {
}

// Issue #3854
// Also see https://github.com/gohugoio/hugo/issues/3977
func TestPageWithDateFields(t *testing.T) {
assert := require.New(t)
pageWithDate := `---
Expand All @@ -735,8 +736,8 @@ weight: %d
---
Simple Page With Some Date`

hasBothDates := func(p *Page) bool {
return p.Date.Year() == 2017 && p.PublishDate.Year() == 2017
hasDate := func(p *Page) bool {
return p.Date.Year() == 2017
}

datePage := func(field string, weight int) string {
Expand All @@ -747,7 +748,7 @@ Simple Page With Some Date`
assertFunc := func(t *testing.T, ext string, pages Pages) {
assert.True(len(pages) > 0)
for _, p := range pages {
assert.True(hasBothDates(p))
assert.True(hasDate(p))
}

}
Expand Down Expand Up @@ -1070,8 +1071,8 @@ func TestMetadataDates(t *testing.T) {
//
// ------- inputs --------|--- outputs ---|
//content filename modfb? D P L M E
{p_D____, "test.md", false, D, D, D, x, x}, // date copied across
{p_D____, "testy.md", true, D, D, D, x, x},
{p_D____, "test.md", false, D, o, D, x, x},
{p_D____, "testy.md", true, D, o, D, x, x},
{p__P___, "test.md", false, P, P, P, x, x}, // pubdate copied across
//{p__P___, "testy.md", true, P, P, P, x, x}, // TODO(bep) date from modTime
{p_DP___, "test.md", false, D, P, D, x, x}, // date -> lastMod
Expand Down Expand Up @@ -1112,6 +1113,9 @@ func TestMetadataDates(t *testing.T) {
checkDate(t, i+1, "LastMod", p.ExpiryDate, test.expExp, fi)

// check Page Params
// TODO(bep) we need to rewrite these date tests to more unit style.
// The params checks below are currently flawed, as they don't check for the
// absense (nil) of a date.
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)
Expand Down

0 comments on commit b6ccbc2

Please sign in to comment.