Open willfaught opened 1 month ago
See #12438
@bep It seems that you didn't read this issue. I linked to https://github.com/gohugoio/hugo/issues/12438 in it. What are your thoughts on the points I made in this issue?
@bep Also, if the ultimate decision is to not revert the .PublishDate behavior, then we should follow through and fix the .PublishDate documentation to reflect the current behavior:
With Hugo’s default configuration, the PublishDate method returns the front matter value. This behavior is configurable, allowing you to set fallback values if the publish date is not defined in front matter.
With Hugo’s default configuration, the PublishDate method returns the front matter value. This behavior is configurable, allowing you to set fallback values if the publish date is not defined in front matter.
The above is still correct. If you add publishDate
to front matter in e.g. mysection/_index.md
then that is the value that's getting published.
The current behaviour matches how we treat both date and lastMod and is what most people would expect.
If you don't want to show publishDate
for sections, then you can do a {{ if .IsPage }}{{ .PublishDate }}{{ end }}
or something..
The above is still correct.
But it's incorrect if no date-like params are set. For other page kinds, if no date-like params are set, then .PublishDate is time.Time{}. That isn't the case for list pages. This special list page behavior is unspecified here and elsewhere.
If you don't want to show publishDate for sections, then you can do a {{ if .IsPage }}{{ .PublishDate }}{{ end }} or something.
I do want to show it if a date-like param is set, according to the configured fallbacks. As I pointed out above, there's currently no portable way to do this.
The current behaviour matches how we treat both date and lastMod
Then my argument should apply to them too. That does admittedly increase the scope of change. If you don't want to make breaking changes (again) like that, then I understand, but then how about a new field that implements the previous behavior? Something like PAGE.PublishDateNotRecursive (similar to PAGE.RegularPagesRecursive)?
(Edited)
I see all my list pages have a value defined for PAGE.PublishDate when there shouldn't be any. This seems to have changed in a recent version, but I don't know which.
Repro for a new/blank site:
layouts/_default/list.html:
layouts/_default/single.html:
content/_index.md:
content/foo.md:
http://localhost:1313/foo/ content:
Expected http://localhost:1313 content:
Actual http://localhost:1313 content:
This change appears to have been part of a bug fix: https://github.com/gohugoio/hugo/issues/12438
I would argue that the previous behavior (where PAGE.PublishDate worked like every other page kind) is better because:
First reported at https://discourse.gohugo.io/t/list-page-publish-date-now-defaults-to-that-of-the-latest-subpage/50634.
What version of Hugo are you using (
hugo version
)?Does this issue reproduce with the latest release?
Yes.