# Generate copyright date from .Lastmod for non-homepage indexes such as /blog/ etc

**URL:** <https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582>\
**Category:** support\
**Created:** [May 27, 2023, 3:21pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582 "2023-05-27T15:21:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![donaldjenkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/donaldjenkins/32/19218_2.png) [@donaldjenkins](https://discourse.gohugo.io/u/donaldjenkins)\
**Post date:** [May 27, 2023, 3:21pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/1 "2023-05-27T15:21:28Z")

</div>

I currently use the following code to generate the date included in the boilerplate copyright text in the footer of my site:

```auto
{{- if .IsHome -}}
  2005-{{ .Site.LastChange.Format "2006" }}
{{- else -}}
  {{ .Date.Format "2006" }}
{{- end -}}

```

This covers the case of the home page (where the range of dates goes from the date of the oldest content, which can be hardcoded, to the most recent, which `{{ .Site.LastChange.Format "2006" }}` has covered.

It also does what I want for individual pages (articles, in my case), where the date displayed will be the date on which the article was initially written (rather than the date when it was last modified, which some users might prefer).

This leaves, however, the issue of non-homepage indexes, such as` /blog/` or, in my case, the [articles](https://www.donaldjenkins.com/articles) and [photos](https://www.donaldjenkins.com/photos) pages, where the corresponding results ( **Copyright © Donald Jenkins 2018** and **Copyright © Donald Jenkins 2019** , respectively) merely display the date-parameter included in the front matter of the corresponding index pages in the `/layout` section, when, in fact, what one would want to display is a range of dates — like on the front page — but this time stretching from the date recorded in the front matter of the oldest page in the /articles and /photos sections respectively, and the most recent one.

Unfortunately, I haven’t been able to find a way of doing this, but suspect it’s possible. Any suggestions as to how would be very gratefully received.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 27, 2023, 7:49pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/2 "2023-05-27T19:49:51Z")

</div>

Does your project have nested sections?

1) This?

```plaintext
content/
├── products/
│ ├── _index.md
│ ├── product-1.md
│ └── product-2.md
└── _index.md

```

2) Or this?

```plaintext
content/
├── products/
│ ├── benefits/
│ │ ├── benefit-1.md
│ │ ├── benefit-2.md
│ │ └── _index.md
│ ├── features/
│ │ ├── feature-1.md
│ │ ├── feature-2.md
│ │ └── _index.md
│ ├── _index.md
│ ├── product-1.md
│ └── product-2.md
└── _index.md

```

3) Or this?

```plaintext
content/
├── products/
│ ├── product-1/
│ │ ├── benefits/
│ │ │ ├── benefit-1.md
│ │ │ ├── benefit-2.md
│ │ │ └── _index.md
│ │ ├── features/
│ │ │ ├── feature-1.md
│ │ │ ├── feature-2.md
│ │ │ └── _index.md
│ │ └── _index.md
│ ├── product-2/
│ │ ├── benefits/
│ │ │ ├── benefit-1.md
│ │ │ ├── benefit-2.md
│ │ │ └── _index.md
│ │ ├── features/
│ │ │ ├── feature-1.md
│ │ │ ├── feature-2.md
│ │ │ └── _index.md
│ │ └── _index.md
│ └── _index.md
└── _index.md

```

---

<div class="post-metadata">

**Author:** ![donaldjenkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/donaldjenkins/32/19218_2.png) [@donaldjenkins](https://discourse.gohugo.io/u/donaldjenkins)\
**Post date:** [May 27, 2023, 10:25pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/3 "2023-05-27T22:25:31Z")

</div>

It looks like this:

```auto
content
├── _index.md
├── articles
│ ├── _index.md
│ ├── a-better-new-decade.md
│ ├── a-plea-in-support-of-mr-obamas-perfectible-health-care-bill.md
│ ├── a-time-to-gather-stones-together.md
│ ├── abomination-in-iran.md
│ ├── alternatives-to-google-search-using-glims-with-blekko-duck-duck-go-or-wolfram-alpha-in-safari 2.md
│ ├── alternatives-to-google-search-using-glims-with-blekko-duck-duck-go-or-wolfram-alpha-in-safari.md
│ ├── an-amazing-mixture-of-roland-petit-the-corps-de-ballet-and-proust.md
│ ├── and-the-word-was-made-flesh-got-that.md
│ ├── backing-up-a-mac-to-amazon-s3-with-arq-the-easiest-safest-and-most-accurate-solution.md
│ ├── benedict-xvi-a-traditionalist-yet-more-in-tune-with-the-realities-of-this-age-than-his-predecessor.md
│ ├── benjamin-millepied-takes-paris-by-storm.md
│ ├── blogging-sequentially-using-writeroom-textmate-and-ecto-or-marsedit.md
│ ├── brexit-time-to-move-on.md
│ ├── brexit-would-be-constitutional-and-economic-suicide.md
│ ├── can-the-fifth-republic-survive-m-sarkozy.md
│ ├── capote-and-the-death-penalty-turning-the-clock-back-to-1967.md
│ ├── cheap-monday-or-how-to-be-thin-poor-and-fashionable.md
│ ├── chopin-such-appropriate-music-for-a-ballet.md
│ ├── connecting-wordpress-lightroom-and-apple-photos.md
│ ├── did-you-even-know-facebook-has-unilaterally-decided-to-share-all-your-data-with-anyone-it-pleases.md
│ ├── does-being-for-the-liberty-of-england-still-mean-being-for-the-protestant-religion.md
│ ├── does-french-tech-have-any-future-at-all.md
│ ├── dont-let-the-french-president-get-elected-by-chance.md
│ ├── feminists-and-homophobes-have-destroyed-a-unique-four-hundred-and-fifty-year-old-english-compromise.md
│ ├── googles-project-fi-a-flexible-and-truly-global-mobile-solution-for-international-travellers.md
│ ├── how-i-effortlessly-draft-and-maintain-squeaky-clean-css-with-sass-and-compass-app.md
│ ├── i-guess-a-moratorium-if-we-get-one-is-better-than-nothing.md
│ ├── i-have-been-known-to-enjoy-rosenkavalier-sometimes.md
│ ├── idomeneo-a-lyrical-turning-point.md
│ ├── improve-your-wordpress-blog-with-marsedit-amazon-cloudfront-and-markdown.md
│ ├── introducing-policymakr.md
│ ├── is-nancy-mitford-no-longer-understood.md
│ ├── itunes-and-steve-jobss-walled-garden-a-major-strategic-blunder-for-apple.md
│ ├── jonathan-littell-is-no-match-for-julien-green.md
│ ├── la-dame-aux-camelias-crusty-old-fogeys-jumping-for-joy.md
│ ├── non-human-animal-rights-the-categorical-imperative-of-our-time.md
│ ├── of-the-virtues-of-representative-democracy.md
│ ├── oh-so-the-pope-abolished-limbo-did-he.md
│ ├── pooling-anglo-french-defence-a-sign-of-progress-or-of-decline.md
│ ├── preparing-this-site-for-the-2020s.md
│ ├── reeder-for-mac-a-stunning-implementation-of-minimalism-elegant-design-and-practicality-in-one-rss-client.md
│ ├── reorganising-this-blog.md
│ ├── should-france-change-her-national-anthem.md
│ ├── sixty-years-a-queen-with-unflinching-grace-and-steadfast-devotion-to-duty.md
│ ├── social-networking-going-towards-an-oligopolistic-closed-shop-system.md
│ ├── sparrow-mail-the-most-elegant-powerful-and-minimalist-mac-email-client.md
│ ├── stuff-i-couldnt-do-without-in-2011.md
│ ├── stuff-i-couldnt-live-without-in-2010.md
│ ├── switching-from-a-dv-to-a-ve-server-on-media-temple.md
│ ├── test-article.md
│ ├── the-absurdity-of-brexit.md
│ ├── the-four-traditionalist-bishops-were-they-ever-validly-excommunicated.md
│ ├── the-french-themselves-dont-realise-how-beautifully-french-les-troyens-is.md
│ ├── the-man-who-dreamt-of-a-modern-rich-democratic-peaceful-iran.md
│ ├── the-new-macbook-air-with-its-first-rate-gpu-and-ssd-its-real-life-performance-belies-the-paper-specs.md
│ ├── the-welcome-trend-away-from-anonymous-posting-on-the-internet.md
│ ├── turn-of-the-decade-tribulations.md
│ ├── what-should-a-tory-government-stand-for-in-2010.md
│ ├── whats-open-anyway-walled-gardens-will-never-stifle-innovation-and-shouldnt-be-confused-with-net-neutrality.md
│ ├── when-in-france-dont-ever-wear-brown-shoes-after-6-pm.md
│ ├── whither-frances-institutions-the-tragic-and-unlamented-end-of-a-thirty-year-golden-age.md
│ ├── why-does-literature-seek-to-give-meaning-to-the-yearning-for-death.md
│ ├── why-i-have-finally-decided-to-blog-in-my-own-name.md
│ ├── why-ive-decided-to-keep-a-blog.md
│ ├── will-mr-obama-bring-the-united-states-any-closer-to-abolishing-the-death-penalty.md
│ ├── would-the-social-register-types-in-new-york-hate-haneke-too.md
│ └── yvonne-princesse-de-bourgogne-gerard-mortier-shuts-his-bolt-pretty-triumphantly.md
├── categories
│ ├── _index.md
│ ├── culture
│ │ └── _index.md
│ ├── literature
│ │ └── _index.md
│ ├── personal
│ │ └── _index.md
│ ├── politics
│ │ └── _index.md
│ ├── religion
│ │ └── _index.md
│ ├── sundry
│ │ └── _index.md
│ └── tech
│ └── _index.md
├── contact
│ └── index.md
├── legal
│ ├── _index.md
│ ├── privacy.md
│ └── terms.md
└── photos
    └── _index.md

```

The pages for which I can’t work out how to display the correct range of copyright dates are: `/articles`, `/photos`, `/legal`, `/contact` and, last but not least, the dynamically-generated term pages (tags, categories)

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 27, 2023, 10:30pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/4 "2023-05-27T22:30:37Z")

</div>

OK, no nested sections. That makes it a bit easier.

If you omit `date` in the front matter of your \_index.md files, the `.Lastmod` date in your section template should return the date of the last modified page.

Please verify.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 27, 2023, 10:32pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/5 "2023-05-27T22:32:19Z")

</div>

For more complicated scenarios, I opened a proposal this morning that will help:  
[https://github.com/gohugoio/hugo/issues/11030](https://github.com/gohugoio/hugo/issues/11030)

That would allow us to range through the pages, build a slice of dates, then get min and max.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 27, 2023, 10:42pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/6 "2023-05-27T22:42:30Z")

</div>

> [@donaldjenkins](#):
>
> dynamically-generated term pages (tags, categories)

I wouldn’t worry about these. Since they are dynamically generated, just use the static start date, and now.Year as the end date.

---

<div class="post-metadata">

**Author:** ![donaldjenkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/donaldjenkins/32/19218_2.png) [@donaldjenkins](https://discourse.gohugo.io/u/donaldjenkins)\
**Post date:** [May 27, 2023, 10:54pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/7 "2023-05-27T22:54:24Z")

</div>

No, unfortunately not. For `/articles`, it displays this:

![SCR-20230527-qkod](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/d/4/d4461d13e5a725dc3990f2517df16eecc81145b4.png)

Then for `/tech`, it displays 2023—as do all the other category pages—despite the fact the most recent [article](https://www.donaldjenkins.com/connecting-wordpress-lightroom-and-apple-photos/) in that category is dated 2019. And `/photos`, for some reason, shows 2019…

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 27, 2023, 10:59pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/8 "2023-05-27T22:59:10Z")

</div>

I’ll need access to your repo.

---

<div class="post-metadata">

**Author:** ![donaldjenkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/donaldjenkins/32/19218_2.png) [@donaldjenkins](https://discourse.gohugo.io/u/donaldjenkins)\
**Post date:** [May 27, 2023, 11:00pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/9 "2023-05-27T23:00:21Z")

</div>

> **[GitHub - donaldjenkins/donaldjenkins: Kensington Theme: Donald Jenkins's site](https://github.com/donaldjenkins/donaldjenkins)**
>
> Kensington Theme: Donald Jenkins's site. Contribute to donaldjenkins/donaldjenkins development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 27, 2023, 11:22pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/10 "2023-05-27T23:22:11Z")

</div>

You are pulling the last modified date from Git, but you don’t have an adequate commit history. For example, the commit date for “content/articles/a-better-new-decade.md” is in 2023, but the article was written in 2011.

Using the commit date for articles day-forward makes sense, but not for legacy pages.

What do you want to do?

---

<div class="post-metadata">

**Author:** ![donaldjenkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/donaldjenkins/32/19218_2.png) [@donaldjenkins](https://discourse.gohugo.io/u/donaldjenkins)\
**Post date:** [May 27, 2023, 11:29pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/11 "2023-05-27T23:29:06Z")

</div>

Ah, that explains it. The individual articles date back to 2005, but I only started committing them to Github when I switched to Hugo earlier this year. Would removing git from the list of last-modified dates in the config do the trick, like so:

```auto
[frontmatter]
date = ["date", "publishDate", "lastmod"]
lastmod = ["lastmod", "date", "publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]

```

?

---

<div class="post-metadata">

**Author:** ![donaldjenkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/donaldjenkins/32/19218_2.png) [@donaldjenkins](https://discourse.gohugo.io/u/donaldjenkins)\
**Post date:** [May 28, 2023, 12:35am UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/12 "2023-05-28T00:35:27Z")

</div>

Implementing your suggestion to remove the reference to git commits from the site Params, I’ve changed the code in the partial to:

```auto
{{- if .IsHome -}}
  2005-{{ .Site.LastChange.Format "2006" }}
{{ else if .IsPage }}
  {{ .Date.Format "2006" }}
{{ else if .Data.Singular }}
  2005-{{ now.Year }}
{{ else if eq .Params.slug "photos" }}
  1933-{{ .Date.Format "2006" }}
{{ else }}
  2005-{{ .Date.Format "2006" }}
{{- end -}}

```

**1.** Taxonomy terms pages (targeted by `{{ else if .Data.Singular }}`) now display the standard start date of 2005 and the current date as the end date (not strictly true, since I actually only started writing about some categories in later years and they don’t all feature a post written in the current year, but there’s probably no obvious way of giving the true range in this case).

**2.** `/articles` now lists the correct end-of-range date, with the start date also being arbitrarily set to 2005 (but this is not a problem in their case).

**3.** `/photos`, rather eerily, displays the correct end date (2019, which is the date of the most recent photograph on that page) despite the fact I didn’t include a date parameter in the json files I’m using to display photos, and also correctly displays 1933 (date of the oldest photograph) as the start date (I wasn’t born then, but can claim to be the successor to the original copyright owners).

This is a clear improvement on the previous setup. The only thing that still needs doing is arranging for the Lastmod date (which I don’t want to use in the other pages) to be displayed on the `/legal/terms` ([terms](https://www.donaldjenkins.com/legal/terms)) and `/legal/privacy` ([privacy policy](https://www.donaldjenkins.com/legal/privacy)) pages, since in this specific case the only possible correct date _is_ the date of the last change. Is there a way of specifically targeting the child pages of `/legal` in the conditional? I haven’t found one.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 28, 2023, 1:59am UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/13 "2023-05-28T01:59:05Z")

</div>

> [@donaldjenkins](#):
>
> Is there a way of specifically targeting the child pages of `/legal` in the conditional? I haven’t found one.

Do a check on .Page.Parent.something.

---

<div class="post-metadata">

**Author:** ![donaldjenkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/donaldjenkins/32/19218_2.png) [@donaldjenkins](https://discourse.gohugo.io/u/donaldjenkins)\
**Post date:** [May 28, 2023, 2:17am UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/14 "2023-05-28T02:17:37Z")

</div>

> [@jmooring](#):
>
> .Page.Parent.something

Hm.

```auto
{{ else if eq .Page.Parent "legal" }}
  {{ .Lastmod.Format "2006" }}

```

doesn’t seem to do the trick.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 28, 2023, 2:56am UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/15 "2023-05-28T02:56:51Z")

</div>

> [@jmooring](#):
>
> Do a check on .Page.Parent.something.

You missed the `something` part.

`.Page.Parent.Title`, etc.

Or compare to `.Page.Section`

---

<div class="post-metadata">

**Author:** ![donaldjenkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/donaldjenkins/32/19218_2.png) [@donaldjenkins](https://discourse.gohugo.io/u/donaldjenkins)\
**Post date:** [May 28, 2023, 7:43am UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/16 "2023-05-28T07:43:44Z")

</div>

Any combination of `.Page.Parent.something` I try throws up the date for `.Date` rather than for `.Lastmod`. I conclude from this that the reason is how .Lastmod and .Date are set by Hugo and how they relate to each other. As I understand, in Go one accesses publish date and last modified date in one of the two following ways:

1. editor-controlled via front-matter in Markdown;

2. automatically extracted from git.

I didn’t want to have to manually update the last modified date in my front matter every time I amended a page, so I didn’t bother to include it, and I use a text editor client to write new posts, so archetypes aren’t relevant to my workflow for new content.

**1.** In `config.toml`, I have:

```auto
[frontmatter]
date = ["date", "publishDate", "lastmod"]
lastmod = ["lastmod", "date", "publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]

```

**2.**.Lastmod isn’t set in my front matter. No longer pulling it from :git (an idea I originally got [here](https://mertbakir.gitlab.io/hugo/last-modified-date-in-hugo/)), as we decided to do earlier, solved the issue for the section pages, but it now means I have no way of targeting the .Lastmod in the `/legal` section.

In other words, I’ve got myself in a configuration in which, when I ask Hugo to display `lastmod`, it displays `date` instead.

I tried adding `lastmod: ":git"` to the two /legal section pages’ front matter, but that didn’t work.

And adding `lastmod = [":fileModTime", “:default”]` to `config.toml`, which I saw suggested [here](https://discourse.gohugo.io/t/rendering-lastmod-date/13968/3), doesn’t work either.

In fact, even hard-coding `lastmod: 2023-05-26T03:20:07+00:00` to their front matter still displays the date!

Yet bizarrely, the following partial works, as you can see on the tope of the [terms](https://www.donaldjenkins.com/legal/terms) and [privacy](https://www.donaldjenkins.com/legal/privacy) pages, at the top of which it correctly generates `lastmod` providing it is set to `['lastmod', ':fileModTime', ':default']` in the front matter, using :

```auto
<span
  >&thinsp;{{ .Lastmod.Format "2" | humanize }} {{ .Lastmod.Format "January" }},
  {{ .Lastmod.Format "2006" }}</span
>

```

and despite displaying `date` rather than `lastmod` in the footer using this code, on the same page:

```auto
{{ else if or (eq .Section "legal") (eq .Params.slug "terms") (eq .Params.slug "privacy") }}
  {{ .Lastmod.Format "2006" }}

```

I’m guessing the solution is to set separate [frontmatter] defaults for that section. Right?

---

<div class="post-metadata">

**Author:** ![donaldjenkins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/donaldjenkins/32/19218_2.png) [@donaldjenkins](https://discourse.gohugo.io/u/donaldjenkins)\
**Post date:** [May 29, 2023, 5:00am UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/17 "2023-05-29T05:00:30Z")

</div>

Just in case anyone is still watching this rather convoluted topic, I solved the issue in the following way:

```auto
{{- if .IsHome -}}
  2005-{{ .Site.LastChange.Format "2006" }}
{{ else if .IsPage }}
  {{ .Date.Format "2006" }}
{{ else if .Data.Singular }}
  2005-{{ now.Year }}
{{ else if eq .Params.slug "photos" }}
  1965-{{ .Date.Format "2006" }}
{{ else if or (eq .Section "legal") (eq .Params.slug "terms") (eq .Params.slug "privacy") }}
  {{ .Lastmod.Format "2006" }}
{{ else }}
  2005-{{ .Lastmod.Format "2006" }}
{{- end -}}

```

This is with the following date settings in `config.toml`:

```auto
[frontmatter]
date = ["date", "publishDate", "lastmod"]
lastmod = ['lastmod', ':fileModTime', ':default']
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]

```

and this in the footer:

```auto
{{ if or (eq .Section "policies") (eq .Params.slug "contact") }}
{{ partial "icons/unlicense.html" . }}&thinsp;This content is <a href="https://github.com/donaldjenkins/Policies/blob/main/LICENSE">unlicensed</a>
{{ else }}
Copyright &#169; Donald Jenkins {{ partial "footer/copyright-year.html" . }}
{{ end }}

```

For any content that doesn’t by nature, despite qualifying as ‘[original works of authorship](https://www.dmlp.org/legal-guide/works-not-covered-copyright)’ require copyright protection, such as the [contact form](https://www.donaldjenkins.com/contact) and legal [policies](https://www.donaldjenkins.com/policies), displaying a copyright notice serves no purpose, and in these cases I have set the Hugo conditional to display the [unlicense](https://unlicense.org/) notice.

For any pages for which you need to use `lastmod`, but haven’t explicitely included it in the post’s front matter, using `:fileModTime` provides a robust alternative to :git.

To sum up the problem this solves, there was an incompatibility, for anyone who doesn’t have a git commit history that matches the age of their content (surely quite a frequent occurrence) between using :git to set `lastmod`, which was the only way of showing a coherent copyright date for pages where it is desirable to display the `lastmod` date rather than the date of first creation, and displaying the full range of years for list pages, which will only show up correctly if `date` is removed from the front matter of the index page and :git is unset as a source for `lastmod`.

One possible avenue for solving this would be the ability to set front matter by section, but I don’t believe it’s currently possible. Since copyright protection isn’t required for policies and contact forms in the first place, not claiming copyright for these sorts of content seems a sensible solution.

---

<div class="post-metadata">

**Author:** ![carlmjohnson](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@carlmjohnson](https://discourse.gohugo.io/u/carlmjohnson)\
**Post date:** [May 30, 2023, 10:21pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/18 "2023-05-30T22:21:30Z")

</div>

This is too much work. Just use `now.Format "2006"` and everything will have the current date. Why would you not extend the copyright on every page?

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 30, 2023, 10:47pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/19 "2023-05-30T22:47:25Z")

</div>

> [@carlmjohnson](#):
>
> Why would you not extend the copyright on every page?

Because it is dishonest.

---

<div class="post-metadata">

**Author:** ![carlmjohnson](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@carlmjohnson](https://discourse.gohugo.io/u/carlmjohnson)\
**Post date:** [May 30, 2023, 11:15pm UTC](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582/20 "2023-05-30T23:15:12Z")

</div>

It’s not dishonest. The copyright is extended by the act of just writing the date on the page. That’s how copyright works post [Copyright Act of 1976 - Wikipedia](https://en.wikipedia.org/wiki/Copyright_Act_of_1976).

[Next page](https://discourse.gohugo.io/t/generate-copyright-date-from-lastmod-for-non-homepage-indexes-such-as-blog-etc/44582.md?page=2)
