I added a small notice that appears on posts older than a year. It was important to me that this notice not show up on photo-only posts — after all, photos rarely lose their relevance. First I wrote a working version myself, then had a language model further optimize the code. Now I’m running the following variant:
{{- /* Tags prüfen */ -}}
{{- $tags := default (slice) .Params.tags -}}
{{- $tagsLower := apply $tags "lower" "." -}}
{{- $hasPhoto := in $tagsLower "photo" -}}
{{- /* Relevantes Datum bestimmen und Stichtag berechnen */ -}}
{{- $pageDate := time.AsTime (or .Lastmod .PublishDate .Date) -}}
{{- $oneYearAgo := (now).AddDate -1 0 0 -}}
{{- /*Hinweis nur auf echten Seiten, mit gültigem Datum, älter als 1 Jahr und nicht beim Tag "photo" */ -}}
{{- if and .IsPage (not $hasPhoto) (gt ($pageDate.Unix) 0) (lt $pageDate $oneYearAgo) -}}
<div class="alert alert-warning">
Hinweis: Dieser Artikel ist über ein Jahr alt. Die Informationen könnten veraltet sein.
</div>
{{- end -}}
The text was automatically translated from German into English. The German quotations were also translated in sense.
Want to reply?
Send me a note via email and let's start a conversation. You can also follow along via RSS or Mastodon.