When using :git for lastmod, pages are tagged with a timestamp of Jan 01, 0001

I was able to overcome my last issue that I posted about with success, got everything working, then realized that my categories for blogs, were showing a date stamp of “Jan 01, 0001” even though none of the other posts or content would show last mod.

I am using the:

And in particular it only appears on this page (using the demo theme for context):

However, I can’t narrow down the cause. I do know it is git, as if I add ":git", to lastmod between lastmod and date here:

enableGitInfo = true
[FrontMatter]
date = [ "date", "publishDate", "lastmod" ]
lastmod = [ "lastmod", "date", "publishDate" ]
publishDate = [ "publishDate", "date" ]
expiryDate = [ "expiryDate" ]

So:

lastmod = [ "lastmod", ":git", "date", "publishDate" ]

That is when all of the issues start to happen.

I narrowed the codebase down to this section, which uses the lastmod frontmatter date in the blog post:


    {{- if ne .Lastmod .Date -}}
    <section class="article-lastmod">
        {{ partial "helper/icon" "clock" }}
        <span>
            {{ T "article.lastUpdatedOn" }} {{ .Lastmod.Format ( or .Site.Params.dateFormat.lastUpdated "Jan 02, 2006 15:04 MST" ) }}
        </span>
    </section>
    <section class="article-lastmod">
        {{ partial "helper/icon" "hash" }}
        <span>
            {{ if .IsPage }}<em>{{ with .GitInfo }}| {{ .Subject }} | {{ .AbbreviatedHash }}{{end }}</em>{{ end }}
        </span>
    </section>

But that section is for a completely different page.

The demo link I gave above, for categories, I believe is using this file:

But I don’t fully understand how git is interfering here:

            <footer class="article-time">
                <time datetime='{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}'>
                    {{- .Date.Format (or .Site.Params.dateFormat.published "Jan 02, 2006") -}}
                </time>
            </footer>

When Git is enabled, it doesn’t matter if lastmod in the frontmatter of a blog post is set to any of the following:

date = "2017-06-23"
lastmod = "2019-05-30"
lastmod = 
lastmod = ""

The category page will still show January 01, 0001.

The versions of the software I am running are:

$ git version                                                                                                                                                                             
git version 2.39.3 (Apple Git-145)
 
$ go version                                                                                                                                                                             
go version go1.21.5 darwin/arm64
 
$ hugo version                                                                                                                                                                            
hugo v0.121.1-00b46fed8e47f7bb0a85d7cfc2d9f1356379b740+extended darwin/arm64 BuildDate=2023-12-08T08:47:45Z VendorInfo=brew

I did read this:

If I set core.quotepath to false, the issue still persists.

An example can be found here:

Two things:

  • I’m not sure the problem is linked to GitInfo, because the exampleSite from the theme “hugo-theme-stack” don’t use it;
  • you have created an index page for all of your categories, and it’s not that the theme did initially. I try to put a date on the file content/blog/categories/Google-Workspace/_index.md, and it works. If I delete the file content/blog/categories/Google-Workspace/_index.md and it does exactly what you want. So you have to fix the way the date is called on the categories page.

Always use lowercase paths for content/your-taxonomy/your-term/_index.md.

Both the example site and their starter template site have an “Example” (in one case called “Test”) where they have an initially created category that does what I am trying to achieve (without GitInfo):

Both of these are categories that are manually created and either contain an image or at least a descriptive category that is not generated from the content. But as you have noticed, neither contain dates.

But that is where I am having difficulty understanding what is going on.

The date here:

Is just calling .Date
{{- .Date.Format (or .Site.Params.dateFormat.published "Jan 02, 2006") -}}

Which should use the date frontmatter from the original post?

In any case, I have modified the footer.html file:

    {{- if gt .GitInfo.CommitDate .Lastmod -}}
    <section class="article-lastmod">
        {{ partial "helper/icon" "clock" }}
        <span>
            {{ T "article.lastUpdatedOn" }} 
            {{ with .GitInfo.CommitDate }}
                {{ . | UTC.dateFormat "January 02, 2006 15:04 MST" }}
            {{ end }}   
            <!-- {{ .GitInfo.CommitDate.Format "January 02, 2006 15:04 MST"  }} -->
        </span>
    </section>
    {{- else if .Lastmod -}}
    <section class="article-lastmod">
        {{ partial "helper/icon" "clock" }}
        <span>
            {{ T "article.lastUpdatedOn" }} {{ .Lastmod.Format ( or .Site.Params.dateFormat.lastUpdated.UTC.Format "January 02, 2006 15:04 MST" ) }}
        </span>
    </section>
    {{- else if ne .GitInfo.CommitDate .Date -}}
    <section class="article-lastmod">
        {{ partial "helper/icon" "clock" }}
        <span>
            {{ T "article.lastUpdatedOn" }} {{ .GitInfo.CommitDate.UTC.Format "January 02, 2006 15:04 MST"  }}
        </span>
    </section>

This seems to be working correctly now. However, I have noticed a different issue, which primarily appears on Cloudflare Pages.

https://community.cloudflare.com/t/re-timezone-format-issue/391130/7

I have tried setting timezones locally in the environment variables using:

TZ
/usr/share/zoneinfo/Etc/UTC

However that doesn’t sem to have worked.

This has been fixed in my private version of the repo.

I find the requirement to use lowercase quite annoying. Especially since most terms are proper names which should be capitalised. And in German we capitalise all nouns. Not being able to use upper case characters at many places in Hugo is very restrictive.

This is a documentation tool. Don’t restrict the Authors in there artistic freedom to us upper case characters.

You can use uppercase nearly everywhere you want (and I do, being German). The one notable exception are the paths to taxonomies and terms. I don’t see why that is a serious restriction.
And why is Hugo a documentation tool more than a blog tool or whatever?

To clarify…

The scope of unexpected behavior described by the OP is very narrow.

Conditions

  1. The term page does not have a date field in front matter, AND
  2. The path to the term page is not lowercase, AND
  3. The enableGitInfo parameter in site configuration is set to true

There’s another condition that I haven’t nailed down yet, perhaps intermittent.

Expected behavior

The term page’s rendered .Date should be the most recent date of the content to which the term is assigned.

Actual behavior

The term page’s rendered .Date is the zero date.

Minimal reproducible example

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

Other than the narrowly defined behavior described above, I am not aware of any problems associated with uppercase or mixed case term page paths.