Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PublishDate does not roll-up to section, taxonomy, or term pages #12438

Open
schu opened this issue Apr 26, 2024 · 6 comments
Open

PublishDate does not roll-up to section, taxonomy, or term pages #12438

schu opened this issue Apr 26, 2024 · 6 comments
Labels
Milestone

Comments

@schu
Copy link

schu commented Apr 26, 2024

What version of Hugo are you using (hugo version)?

hugo v0.125.4+extended darwin/arm64 BuildDate=2024-04-25T13:27:26Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes.

Description

After upgrading to v0.125 I see changes like the following for categories/index.xml and tags/index.xml files:

-      <pubDate>Sat, 27 Oct 2018 08:30:00 +0000</pubDate>
+      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>

For subindex files like categories/foo/index.xml the pubDate is set to the expected value, i.e. the generated output is identical to versions < v0.125.

From looking at the changelog and commit f0a26cf58e9bfbe55c091d51a4133bc22cad5d1f it's not clear to me what needs to be changed in order to retain the previous (default) selection of values for pubDate? Am I missing something?

Also, with above hugo version {{ hugo.Version }} doesn't seem to be set, resulting in the following output for the generator tag:

-    <generator>Hugo -- gohugo.io</generator>
+    <generator>Hugo</generator>
@jmooring
Copy link
Member

@schu

The version string was added to the generator tag in v0.125.0 to address #11692, and was removed in v0.125.3 to address #12300 (comment). We should have closed #11692 as "won't fix".

I'll look into the zero pubdate problem.

@jmooring jmooring self-assigned this Apr 26, 2024
@jmooring jmooring changed the title Unexpected pubDate values for categories/index.xml and tags/index.xml files PublishDate does not roll-up to term or section pages Apr 26, 2024
@jmooring
Copy link
Member

jmooring commented Apr 26, 2024

The Date and Lastmod roll-up to section, taxonomy, and term pages. The PublishDate does not "roll-up".

I think the PublishDate should roll-up to the latest date before now(). If we rolled-up dates after now(), that would cause the section, taxonomy, or term page to not be published even if there's other descendant content.

Applicable to:

  • Automatic section, taxonomy, and term pages
  • Section, taxonomy, and term pages without Date and PublishDate

This isn't something new (i.e., same behavior in v0.122.0).

The test case below does not test for what should happen with publish dates greater than now() as described above.

Failing test
func TestFoo(t *testing.T) {
	t.Parallel()

	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]
---
`

	// Test without publishDate in front matter.
	b := hugolib.Test(t, files)

	b.AssertFileContent("public/s1/index.html", `
		Date: 2024-04-03
		PublishDate: 2024-04-03
		Lastmod: 2024-04-04
	`)

	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 = hugolib.Test(t, files)

	b.AssertFileContent("public/s1/index.html", `
		Date: 2024-04-03
		PublishDate: 2024-04-03
		Lastmod: 2024-04-03
	`)

	b.AssertFileContent("public/tags/index.html", `
		Date: 2024-04-03
		PublishDate: 2024-04-03
		Lastmod: 2024-04-03
	`)

	b.AssertFileContent("public/tags/t1/index.html", `
		Date: 2024-04-03
		PublishDate: 2024-04-03
		Lastmod: 2024-04-03
	`)
}

@jmooring jmooring changed the title PublishDate does not roll-up to term or section pages PublishDate does not roll-up to section, taxonomy, or term pages Apr 26, 2024
@bep
Copy link
Member

bep commented Apr 30, 2024

I think the PublishDate should roll-up to the latest date before now().

Yea, that sounds reasonable.

@bep bep modified the milestones: v0.125.4, v0.125.5, v0.125.6, v0.125.7 Apr 30, 2024
@jmooring jmooring removed their assignment May 3, 2024
@bep bep modified the milestones: v0.125.7, v0.127.0 May 15, 2024
@schu
Copy link
Author

schu commented May 15, 2024

Is there a workaround that I could apply to get back the old behavior?

Or is there a chance to revert to the old behavior until a working fix is found?

@jmooring
Copy link
Member

Override the embedded RSS template, and change this line:

<pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>

To:

<pubDate>{{ (or .PublishDate .Date).Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate> 

If the page has a publication date, use that, else use the date.

schu added a commit to schu/about-blank that referenced this issue May 15, 2024
Add a custom `rss.xml` default layout with a workaround for a
`PublishDate` regression for Hugo v0.125 and newer where the
`PublishDate` does not get set correctly for all generated files.
Details can be found here:

gohugoio/hugo#12438

Hugo documentation:

https://gohugo.io/templates/rss/#template-lookup-order

The `rss.xml` file is based on the upstream default template found here:

```
curl -LO https://raw.githubusercontent.com/gohugoio/hugo/3d40aba512931031921463dafc172c0d124437b8/tpl/tplimpl/embedded/templates/_default/rss.xml
```

The changed line is:

```
<pubDate>{{ (or .PublishDate .Date).Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
```
@schu
Copy link
Author

schu commented May 15, 2024

Override the embedded RSS template [...]

Thanks, that worked.

For other readers: download the default rss.xml template to layouts/_default/rss.xml and change the pubDate line as shown above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants