Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Feb 23, 2018
1 parent 247a82f commit 62cafa7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions hugolib/page_frontmatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func (f frontmatterHandler) handleDates(d frontMatterDescriptor) error {
d.dates.Lastmod = d.dates.Date
}

// TODO(bep) date decide vs https://github.com/gohugoio/hugo/issues/3977
if d.dates.PublishDate.IsZero() {
//d.dates.PublishDate = d.dates.Date
}

if d.dates.Date.IsZero() {
d.dates.Date = d.dates.Lastmod
}
Expand Down
25 changes: 17 additions & 8 deletions hugolib/page_frontmatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,20 @@ func doTestFrontMatterDates(t *testing.T, defaultDateSetting string) {

// See http://www.imdb.com/title/tt0133093/
for _, lastModKey := range []string{"lastmod", "modified"} {
testDate = testDate.Add(24 * time.Hour)
t.Log(lastModKey, testDate)
for _, lastModDate := range []time.Time{testDate, sentinel} {
for _, dateKey := range []string{"date"} {
testDate = testDate.Add(24 * time.Hour)
t.Log(dateKey, testDate)
for _, dateDate := range []time.Time{testDate, sentinel} {
for _, pubDateKey := range []string{"publishdate", "pubdate", "published"} {
testDate = testDate.Add(24 * time.Hour)
t.Log(pubDateKey, testDate)
for _, pubDateDate := range []time.Time{testDate, sentinel} {
for _, expiryDateKey := range []string{"expirydate", "unpublishdate"} {
testDate = testDate.Add(24 * time.Hour)
t.Log(expiryDateKey, testDate)
for _, expiryDateDate := range []time.Time{testDate, sentinel} {
d := frontMatterDescriptor{
frontmatter: make(map[string]interface{}),
Expand All @@ -115,12 +120,6 @@ func doTestFrontMatterDates(t *testing.T, defaultDateSetting string) {
expLastMod, expDate, expPubDate, expExiryDate = zero, zero, zero, zero
)

if lastModDate != sentinel {
d.frontmatter[lastModKey] = lastModDate
expLastMod = lastModDate
expDate = lastModDate
}

if dateDate != sentinel {
d.frontmatter[dateKey] = dateDate
expDate = dateDate
Expand All @@ -129,6 +128,18 @@ func doTestFrontMatterDates(t *testing.T, defaultDateSetting string) {
if pubDateDate != sentinel {
d.frontmatter[pubDateKey] = pubDateDate
expPubDate = pubDateDate
if expDate.IsZero() {
expDate = expPubDate
}
}

if lastModDate != sentinel {
d.frontmatter[lastModKey] = lastModDate
expLastMod = lastModDate

if expDate.IsZero() {
expDate = expPubDate
}
}

if expiryDateDate != sentinel {
Expand Down Expand Up @@ -173,8 +184,6 @@ func assertFrontMatterDate(assert *require.Assertions, d frontMatterDescriptor,
if expected != param {
assert.Fail("Params check failed", "[%s] Expected:\n%q\nGot:\n%q", dateField, expected, param)
}
assert.Equal(expected, param)

}
}

Expand Down

0 comments on commit 62cafa7

Please sign in to comment.