mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Fix it so publishDate rolls up to section, taxonomy, or term pages
Fixes #12438
This commit is contained in:
parent
932ab4c058
commit
7b6dafc53a
3 changed files with 90 additions and 3 deletions
|
@ -1428,7 +1428,7 @@ func (sa *sitePagesAssembler) applyAggregates() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if wasZeroDates {
|
if wasZeroDates {
|
||||||
pageBundle.m.pageConfig.Dates.UpdateDateAndLastmodIfAfter(sp.m.pageConfig.Dates)
|
pageBundle.m.pageConfig.Dates.UpdateDateAndLastmodAndPublishDateIfAfter(sp.m.pageConfig.Dates)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pageBundle.IsHome() {
|
if pageBundle.IsHome() {
|
||||||
|
@ -1565,7 +1565,7 @@ func (sa *sitePagesAssembler) applyAggregatesToTaxonomiesAndTerms() error {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.m.pageConfig.Dates.UpdateDateAndLastmodIfAfter(sp.m.pageConfig.Dates)
|
p.m.pageConfig.Dates.UpdateDateAndLastmodAndPublishDateIfAfter(sp.m.pageConfig.Dates)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,3 +266,86 @@ Home's Date should be equal mydata date: true
|
||||||
Full time: 6:00:00 am UTC
|
Full time: 6:00:00 am UTC
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPublisDateRollupIssue12438(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
// To future Hugo maintainers, this test will start to fail in 2099.
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ['home','rss','sitemap']
|
||||||
|
[taxonomies]
|
||||||
|
tag = 'tags'
|
||||||
|
-- layouts/_default/list.html --
|
||||||
|
Date: {{ .Date.Format "2006-01-02" }}
|
||||||
|
PublishDate: {{ .PublishDate.Format "2006-01-02" }}
|
||||||
|
Lastmod: {{ .Lastmod.Format "2006-01-02" }}
|
||||||
|
-- layouts/_default/single.html --
|
||||||
|
{{ .Title }}
|
||||||
|
-- content/s1/p1.md --
|
||||||
|
---
|
||||||
|
title: p1
|
||||||
|
date: 2024-03-01
|
||||||
|
lastmod: 2024-03-02
|
||||||
|
tags: [t1]
|
||||||
|
---
|
||||||
|
-- content/s1/p2.md --
|
||||||
|
---
|
||||||
|
title: p2
|
||||||
|
date: 2024-04-03
|
||||||
|
lastmod: 2024-04-04
|
||||||
|
tags: [t1]
|
||||||
|
---
|
||||||
|
-- content/s1/p3.md --
|
||||||
|
---
|
||||||
|
title: p3
|
||||||
|
lastmod: 2099-05-06
|
||||||
|
tags: [t1]
|
||||||
|
---
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
// Test without publishDate in front matter.
|
||||||
|
b := Test(t, files)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/s1/index.html", `
|
||||||
|
Date: 2099-05-06
|
||||||
|
PublishDate: 2024-04-03
|
||||||
|
Lastmod: 2099-05-06
|
||||||
|
`)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/tags/index.html", `
|
||||||
|
Date: 2024-04-03
|
||||||
|
PublishDate: 2024-04-03
|
||||||
|
Lastmod: 2024-04-04
|
||||||
|
`)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/tags/t1/index.html", `
|
||||||
|
Date: 2024-04-03
|
||||||
|
PublishDate: 2024-04-03
|
||||||
|
Lastmod: 2024-04-04
|
||||||
|
`)
|
||||||
|
|
||||||
|
// Test with publishDate in front matter.
|
||||||
|
files = strings.ReplaceAll(files, "lastmod", "publishDate")
|
||||||
|
|
||||||
|
b = Test(t, files)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/s1/index.html", `
|
||||||
|
Date: 2099-05-06
|
||||||
|
PublishDate: 2024-04-04
|
||||||
|
Lastmod: 2099-05-06
|
||||||
|
`)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/tags/index.html", `
|
||||||
|
Date: 2024-04-03
|
||||||
|
PublishDate: 2024-04-04
|
||||||
|
Lastmod: 2024-04-03
|
||||||
|
`)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/tags/t1/index.html", `
|
||||||
|
Date: 2024-04-03
|
||||||
|
PublishDate: 2024-04-04
|
||||||
|
Lastmod: 2024-04-03
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
|
@ -57,13 +57,17 @@ func (d Dates) IsDateOrLastModAfter(in Dates) bool {
|
||||||
return d.Date.After(in.Date) || d.Lastmod.After(in.Lastmod)
|
return d.Date.After(in.Date) || d.Lastmod.After(in.Lastmod)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dates) UpdateDateAndLastmodIfAfter(in Dates) {
|
func (d *Dates) UpdateDateAndLastmodAndPublishDateIfAfter(in Dates) {
|
||||||
if in.Date.After(d.Date) {
|
if in.Date.After(d.Date) {
|
||||||
d.Date = in.Date
|
d.Date = in.Date
|
||||||
}
|
}
|
||||||
if in.Lastmod.After(d.Lastmod) {
|
if in.Lastmod.After(d.Lastmod) {
|
||||||
d.Lastmod = in.Lastmod
|
d.Lastmod = in.Lastmod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if in.PublishDate.After(d.PublishDate) && in.PublishDate.Before(htime.Now()) {
|
||||||
|
d.PublishDate = in.PublishDate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Dates) IsAllDatesZero() bool {
|
func (d Dates) IsAllDatesZero() bool {
|
||||||
|
|
Loading…
Reference in a new issue