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>
Are you setting lastMod in the front matter of your content pages?
Are you setting any other date values in the front matter of your content pages?
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?
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.
As above, date and lastmod only.
The top level (which returning homepage) is indeed in _index.md
a. Yes, this got set this as well as:
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?
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…
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 }}