Skip to content

Instantly share code, notes, and snippets.

@nathnp
Last active July 20, 2024 01:33
Show Gist options
  • Select an option

  • Save nathnp/00cefda8e28f4d28ac929c6e930460da to your computer and use it in GitHub Desktop.

Select an option

Save nathnp/00cefda8e28f4d28ac929c6e930460da to your computer and use it in GitHub Desktop.
Post age warning for Hugo
{{- $PostYear := .Date -}}
{{- $CurrentYear := time.Now -}}
{{- $YearDifU := math.Sub $CurrentYear.Unix $PostYear.Unix -}}
{{- $TPostYear := .Date | time.Format "2006" | int -}}
{{- $YearDif := math.Sub (now.Year | int) $TPostYear -}}
{{- if ge $YearDifU 31536000 -}}
<p class="notice">
This post is over {{ if eq $YearDif 1 }} a year{{- else -}}{{- $YearDif }} years{{- end }} old. The information here may be out of date, and may not reflect my current thoughts or opinions.
</p>
{{- end -}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment