-
-
Save softplus/176dcbb5c5901a6217fe4f265e29ebba to your computer and use it in GitHub Desktop.
render-link.html (with /nofollow/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{- $linkurl := .Destination }} | |
{{- $relval := "" }} | |
{{- $targetval := "" }} | |
{{- $classval := "" }} | |
{{- if strings.HasPrefix $linkurl "/nofollow/#" }} | |
{{- $relval = printf "%s %s" $relval "nofollow" }} | |
{{- $urlparts := split $linkurl "#" -}} | |
{{- $linkurl = index $urlparts 1 }} | |
{{- end -}} | |
{{- if strings.HasSuffix $linkurl "#?" }} | |
{{- $relval = printf "%s %s" $relval "nofollow" }} | |
{{- $urlparts := split $linkurl "#" -}} | |
{{- $linkurl = index $urlparts 0 }} | |
{{- end -}} | |
{{- if strings.HasPrefix $linkurl "http" }} | |
{{- $targetval = printf "%s %s" $targetval "_blank" }} | |
{{- $relval = printf "%s %s" $relval "noopener" }} | |
{{- $classval = printf "%s %s" $classval "external" }} | |
{{- end -}} | |
<a href="{{ $linkurl | safeURL }}" | |
{{- with .Title}} title="{{ trim . " " }}"{{ end -}} | |
{{- with $relval}} rel="{{ trim . " " }}"{{ end -}} | |
{{- with $targetval}} target="{{ trim . " " }}"{{ end -}} | |
{{- with $classval}} class="{{ trim . " " }}"{{ end -}} | |
>{{ .Text | safeHTML }}</a> | |
{{- if strings.HasPrefix $linkurl "http" }} | |
{{- if gt (sub now.Year .Page.Date.Year) 5 }} | |
{{- $relval = printf "%s %s" $relval "nofollow" }} | |
(<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 -}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment