Make sitemap always use UTC time instead of the time retrieved from gitInfo

Is it possible to always use UTC time in the sitemap?

I created the following example:

This example includes layouts/_default/sitemap.xml, which replaces “-07:00” in the embedded layout with “+00:00”. But the generated sitemap contains

<url>
    <loc>https://example.org/page/</loc>
    <lastmod>2024-05-14T21:02:53+00:00</lastmod>
  </url>

, while the real commit time of page.md is 2024-05-14T21:02:53-07:00. GMT-07:00 is the timezone in the relevant git commit.

I understand that robot readers can probably perform timezone conversion by themselves, but I would prefer some privacy on the geolcation where the page was modified on some sites.

In the sitemap template do this…

.Lastmod.UTC.Format "2006-01-02T15:04:05-07:00"

…instead of this:

.Lastmod.Format "2006-01-02T15:04:05-07:00"

See https://gohugo.io/methods/time/utc/.

The bit inside of the quotes is a layout string; it affects how a time.Time value is rendered. The layout string is described here:
https://gohugo.io/functions/time/format/

1 Like

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