gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.32k stars 7.43k forks source link

List page publish date now defaults to that of the latest subpage #12653

Open willfaught opened 1 month ago

willfaught commented 1 month ago

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:

<html>
<body>
{{.PublishDate}}
</body>
</html>

layouts/_default/single.html:

<html>
<body>
{{.Title}}
{{.PublishDate}}
</body>
</html>

content/_index.md:

+++
title = "Main"
+++

content/foo.md:

+++
title = "Foo"
date = 2022-04-02T12:45:03-07:00
+++

http://localhost:1313/foo/ content:

Foo 2022-04-02 12:45:03 -0700 PDT

Expected http://localhost:1313 content:

0001-01-01 00:00:00 +0000 UTC

Actual http://localhost:1313 content:

2022-04-02 12:45:03 -0700 PDT

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)?

$ hugo version
hugo v0.128.2+extended darwin/arm64 BuildDate=2024-07-04T08:13:25Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes.

bep commented 1 month ago

See #12438

willfaught commented 1 month ago

@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?

willfaught commented 1 month ago

@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.

bep commented 1 month ago

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..

willfaught commented 1 month ago

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)