Disclaimer on over a year since last updated posts

When a post hasn’t been updated for 1 year, I’m trying to show a disclaimer that my opinion may have changed.

It was inspired by this blog post: If this post is published on my blog… - Jan-Lukas Else

I’m Trying with this code:

{{ $date := .Date }}
{{ $oneYearAgo := (now.AddDate(-1, 0, 0)) }}

{{ if and (lt $date $oneYearAgo) (ne .Next.FirstTimePublished $date) }}
  <p class="disclaimer">This entry is already over one year old. It may no longer be up to date. Opinions may have changed.</p>
{{ end }}

Hmmm… The first mistake I can see is the use of parentheses with .AddDate.

The second one would be this (ne .Next.FirstTimePublished $date), which frankly is new to me.

{{ $currentTime := (time now) }}
{{ $delta := $currentTime.Sub (time .Date ) }}
{{ if gt $delta.Hours 8760 }}
	This entry is already over one year old. It may no
	longer be up to date. Opinions may have changed.
{{ end }}

Probably not the best solution but it works.

1 Like

fairly new to coding, I’ve tried this new thing called ChatGPT but I think it’s as dumb as me :sweat_smile:
Thank you.

Thank you. It worked for me.

I have posts that are over a year old but were recently updated. It seems they are affected. Is there a way to make it respond to the last modified date?