Setting lastmod date for a page when list updated

Hi,
Got a general question, not really a pain but would like if is possible to get this done automatically.

When I publish new post on that page the content added to the list is set with date but the page itself, despite been updated during build, as a last mod will still display lastmod as per front matter. This is in fact correct behaviour hence no issue.

On the page above you will see that content was added 22/04/2023 and list on the page updated but the page itself reporting lastmod from front matter.

Wonder if there are other ways to report lastmod for page with list, maybe based on last item added to the list as a lastmod date?

My initial though was that removing lastmod from front matter will result default return of lastmod based on bage build but my assumption is incorrect (was set as 18-01-2021 20:21).

The page contain like

## 2023

{{< dziennik-lotow "2023" >}}

and shortcode

<div class="thumbnails"> 
  {{ $year := .Get 0 }}
  {{ range .Site.Pages }}
    {{ if in .Params.categories "Dziennik lotĂłw" }}
      {{ if eq (.Date.Format "2006") $year }}

    <div class="thumbnail-description">
      <a href="{{ .Permalink }}">
        {{ partial "featuredImage-grid.html" . }}
        {{ .Title }}
      </a>
    </div>
    
      {{ end }}
    {{ end }}
  {{ end }}
</div>

To help me understand…

  1. Is enableGitInfo set to true in your site configuration?
  2. Are you using the default front matter configuration?
  3. Are you setting lastMod in the front matter of your content pages?
  4. Are you setting any other date values in the front matter of your content pages?
  5. For top-level sections, do you have an _index.md file? If yes, are you:
    a. Setting lastMod in the front matter?
    b. Setting any other date values in the front matter?
  1. No, I haven’t set that or tried before. I tried now and it and .Lastmod returning 2023-03-03T07:00:59+00:00 for that page

  2. I think so, the dates in frontmatter for that page are:

---
date: "2021-01-18T20:21:00"
lastmod: "2022-06-16T22:21:00"
---
  1. Yes, and this is what I want to remove if needed if the desired output is received. I tend to forget to update this when added post to the page which is taken through shortcode, this is why I am looking if there is other way.

  2. As above, date and lastmod only.

  3. The top level (which returning homepage) is indeed in _index.md
    a. Yes, this got set this as well as:

---
date: "2016-01-26T22:23:00"
lastmod: "2021-12-11T15:24:00"
---

b. No.

I understand that there may be no ideal solution for that, so if is not possible, I will use the closest approach.

I need a definitive answer, yes or no. Does your site configuration exclude the frontmatter key, or does it contain exactly this, or something different than this?

[frontmatter]
date = ['date', 'publishDate', 'lastmod']
expiryDate = ['expiryDate']
lastmod = [':git', 'lastmod', 'date', 'publishDate']
publishDate = ['publishDate', 'date']

Ah,
In site configuration there is nothing in relation to frontmatter hence its what Hugo providing by default. So the answer is Yes, defaults.

A few thoughts:

  1. If your _index.md file contains content (i.e., markdown), then the last mod date should (maybe) be the date that the markdown was modified. Depends on your goal…
  2. It is much easier to use the Git author date. Setting lastmod in front matter means that you need to remember to update it every time.

To get the most recent mod date while ranging through a page collection, you can do:

{{ $lastMod := 0 }}
{{ range .Pages }}
  {{ if gt .Lastmod $lastMod }}
    {{ $lastMod = .Lastmod }}
  {{ end }}
{{ end }}

{{ $lastMod | time.Format $formatString }}
3 Likes