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

RSS template has incorrect value for lastBuildDate #11600

Closed
tastapod opened this issue Oct 24, 2023 · 6 comments · Fixed by #11636
Closed

RSS template has incorrect value for lastBuildDate #11600

tastapod opened this issue Oct 24, 2023 · 6 comments · Fixed by #11636

Comments

@tastapod
Copy link
Contributor

tastapod commented Oct 24, 2023

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

$ hugo version
hugo v0.119.0-b84644c008e0dc2c4b67bd69cccf87a41a03937e+extended darwin/arm64 BuildDate=2023-09-24T15:20:17Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes

Steps to reproduce

  1. Build site with hugo command
  2. Check the top-level /index.xml file

Description

In Hugo 0.119, the internal RSS template has a <lastBuildDate> field based on .Date, which is the date in the site's top-level _index.md file (or the _index.md file for the section or category for sub-feeds, I presume).

Instead it should either be the date the RSS file was built or the date of the most recent published post, so RSS readers can tell whether anything has changed.

I am doing the latter in the following fragment, in a custom /layouts/rss.xml template based on the internal one:

{{- $lastBuildDate := (index $pages.ByDate.Reverse 1).Date -}}
...
<lastBuildDate>{{ $lastBuildDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}

I am happy to submit a PR with this change. I can't see it breaking anything except for the case where $pages is empty.

Using the current build time is even easier:

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

I prefer the most recent post date; it feels more RSS-like. The main thing is that the current /index.xml bases the date on /_index.md, which in my case is August 2013!

@jmooring
Copy link
Member

jmooring commented Oct 26, 2023

Yes, we should change this, but use .Lastmod instead of .Date and remember that array/slice indexes are zero-based:

<lastBuildDate>{{ (index $pages.ByLastmod.Reverse 0).Lastmod.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>

Please submit PR.

@tastapod
Copy link
Contributor Author

Ah thanks, I misread the collections.Index docs. Will do.

@tastapod
Copy link
Contributor Author

I found another RSS template, which is for the Hugo docs site. This has the same bug.

I propose factoring out the expression in line 20 so the first line of the template is:

{{- $pages := first 50 (where .Site.RegularPages "Type" "in" (slice "news" "showcase")) -}}

then use the same (index $pages.ByLastmod.Reverse 0).Lastmod expression for the lastModDate field.

WDYT?

@jmooring
Copy link
Member

I think you should focus on the original issue, and raise a separate issue in the docs repository.

@tastapod
Copy link
Contributor Author

Ok will do.

I'm getting test failures on a fresh checkout. I've asked for help but nothing yet. I'm pretty sure this change won't make things any worse, but I have an allergic reaction to checking in code with broken tests!

tastapod added a commit to tastapod/hugo that referenced this issue Oct 30, 2023
Set the `<lastBuildDate>` field to be the most recent Lastmod date
of all the posts in the current selection.

Fixes gohugoio#11600
tastapod added a commit to tastapod/hugo that referenced this issue Nov 1, 2023
Fixes gohugoio#11600

Co-authored-by: Joe Mooring <joe@mooring.com>
bep pushed a commit that referenced this issue Jan 25, 2024
Set the `<lastBuildDate>` field to be the most recent Lastmod date
of all the posts in the current selection.

Fixes #11600
bep pushed a commit that referenced this issue Jan 25, 2024
Fixes #11600

Co-authored-by: Joe Mooring <joe@mooring.com>
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants