Adding archive.org links to old posts in Hugo

Since there’s so much old content here, I thought I’d add links to archive.org in links in older posts. At least this way people have a chance to see what might have been there earlier.

Following adding nofollow in hugo I added the following to the render-link.html file:

{{- if strings.HasPrefix $linkurl "http" }}
    {{- if gt (sub now.Year .Page.Date.Year) 5 }} (<a 
        href="https://web.archive.org/web/{{ .Page.Date.Year }}*/{{ $linkurl }}"
        {{- with $relval}} rel="{{ trim . " " }}"{{ end -}}
        {{- with $targetval}} target="{{ trim . " " }}"{{ end -}}
        {{- with $classval}} class="{{ trim . " " }}"{{ end -}}
        >archive.org</a>)
    {{- end -}}
{{- end -}}

If you wanted to do this without any of the variables I used, this will also work:

{{- if strings.HasPrefix .Destination "http" }}
    {{- if gt (sub now.Year .Page.Date.Year) 5 }} (<a 
        href="https://web.archive.org/web/{{ .Page.Date.Year }}*/{{ .Destination }}"
        rel="noopener noreferrer" target="_blank">archive.org</a>)
    {{- end -}}
{{- end -}}

Comments / questions

There's currently no commenting functionality here. If you'd like to comment, please use Twitter and @me there. Thanks!

Tweet about this - and/or - search for latest comments / top comments

Related pages