If eq .Date .Lastmod (0.123.8)

Does something changed in regards to Lastmod field.

I got some posts that have DATE, and otheres that have DATE and LASTMOD fields.

This used to return this correctly

{{ if eq .Date .Lastmod }}
True
{{ else }}
False
{{ end }}

But right now, if post got DATE only, it returning False, and when have DATE and LASTMOD (both different) returning False as well.

Noticed, that here Configure Hugo | Hugo
the default frontmatter for lastmod include :git first, so I removed it in my configuration as follow:

[frontmatter]
  date = ['date', 'publishdate', 'pubdate', 'published', 'lastmod', 'modified']
  expiryDate = ['expirydate', 'unpublishdate']
  lastmod = ['lastmod', 'modified', 'date', 'publishdate', 'pubdate', 'published']
  publishDate = ['publishdate', 'pubdate', 'published', 'date']

even that {{ .Date }} and {{ .Lastmod }} reporting same figure, for eq is still False.

Bug?


This is working:

{{ $date := .Date.Format "2006-01-02T15:04:05.000" }}
{{ $lastmod := .Lastmod.Format "2006-01-02T15:04:05.000" }}
{{ if eq $date $lastmod }}
True
{{ else }}
False
{{ end }}

Simillar issue reported when using (from gohugoioTheme/layouts/partials/opengraph/opengraph.html at b1860f34918076c90101316a052165501ee61dad · gohugoio/gohugoioTheme · GitHub)

{{ with .Lastmod }}<meta property="article:modified_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }}

the .Lastmod always reporting it as “having” LASTMOD even when not specified

I’m not able to reproduce this, so I’m probably missing some details.

site config

baseURL = 'https://example.org/'
languageCode = 'en-US'
title = 'Hugo Forum Topic #48798'

content/posts/post-1.md

---
title: Post 1
date: 2024-03-13T06:00:00-07:00
---

layouts/_default/single.html

{{ .Date | warnf "date = %#v" }}
{{ .Lastmod | warnf "lastmod = %#v" }}

{{ if eq .Date .Lastmod }}
  {{ warnf "TRUE" }}
{{ else }}
  {{ warnf "FALSE" }}
{{ end }}

console output

Start building sites … 
hugo v0.123.8-5fed9c591b694f314e5939548e11cc3dcb79a79c+extended linux/amd64 BuildDate=2024-03-07T13:14:42Z VendorInfo=gohugoio

WARN  date = time.Date(2024, time.March, 13, 6, 0, 0, 0, time.Local)
WARN  lastmod = time.Date(2024, time.March, 13, 6, 0, 0, 0, time.Local)
WARN  TRUE

test site

git clone --single-branch -b hugo-forum-topic-48798 https://github.com/jmooring/hugo-testing hugo-forum-topic-48798
cd hugo-forum-topic-48798
hugo

Interesting.

I just test on my test environment and also cannot reproduce it but in one particular repo this issue persist.

If you don’t mind, as repo is private, I will add you to it and when you can, could you have a look?

I have used your code and noticed where there is an issue:

WARN  date = time.Date(2024, time.February, 22, 6, 0, 0, 0, time.Location("Europe/London"))
WARN  lastmod = time.Date(2024, time.February, 22, 6, 0, 0, 0, time.UTC)

also

WARN  date = time.Date(2023, time.July, 5, 6, 0, 0, 0, time.Location("Europe/London"))
WARN  lastmod = time.Date(2023, time.July, 5, 6, 0, 0, 0, time.Local)

Date is reported in different timezone than Lastmod date. Any reason?

I got this in config

timeZone = "Europe/London"

Are both dates fully qualified?
Do you have timeZone set in site config?
Anything else different between the test site and your live site?

Date in front matter

date: "2024-03-13T08:40:00"

lastmod not specified.

log:

WARN  date = time.Date(2024, time.March, 13, 8, 40, 0, 0, time.Location("Europe/London"))
WARN  lastmod = time.Date(2024, time.March, 13, 8, 40, 0, 0, time.UTC)

On my test site I am using format with timezone, this is why is not showing the issue

date: 2022-03-30T13:31:58+01:00

but for this particular site I am reporting differently and specifying timezone in config

timeZone = "Europe/London"

OK, I can reproduce the difference between v0.122.0 and v0.123.8 with an unqualified date string.

1 Like

This one’s weird because, as you pointed out, the values are correct if date-formatted. The values themselves are both correct (they point to the same moment in time), but they are (obviously) stored differently internally.

If I set:

timeZone = "America/Los_Angeles"

I get this:

WARN  date = time.Date(2024, time.March, 13, 6, 0, 0, 0, time.Location("America/Los_Angeles"))
WARN  lastmod = time.Date(2024, time.March, 13, 6, 0, 0, 0, time.Local)

Again, both are correct… they point to the same moment in time.

1 Like

Thanks, I will use my workaround from 1st post, that is working and will observe progress.

Will you raise issue on GitHub?

https://github.com/gohugoio/hugo/issues/12236

1 Like

@idarek In the interest of tracking forum topics related to v0.123.x that do not have a corresponding GitHub issue, I am marking this resolved.

These are the forum topics related to v0.123.x that do not yet have a corresponding GitHub issue (for good reasons):

v0.123.0 (unsolved) (We’re doing pretty well here)

1 Like

@idarek

Use this instead…

{{ if .Date.Equal .Lastmod  }}

https://gohugo.io/methods/time/equal/

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.