Highlight old posts in Hugo

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. ...

October 21, 2025 · 1 min · 182 words

Externe Umleitung in Hugo

As a blogger today, I wanted to redirect URLs that point to a subdirectory to an external destination. In the blog post ‘Using Hugo as a redirect service’ by Daniel Terhorst-North I came across a very lean solution. To achieve this, the following file must be created in the theme folder: /layouts/redirect/single.html. The following source code must be added to the file: {{- template "_internal/alias.html" (dict "Permalink" .Params.target) -}} You can now create a file and define the redirect with the following four lines. The filename also determines the directory of the source URL: ...

December 17, 2023 · 1 min · 117 words