advise browser not to set referrerer for external links and open them in new tab

This commit is contained in:
Marcel Straub
2022-01-17 23:45:55 +01:00
parent bfa5ee4b41
commit efdd7c9899

View File

@@ -0,0 +1,18 @@
{{- $parsedTitle := dict -}}
{{- with .Title -}}
{{- $parsedTitle = partial "functions/parse-title-attribute.html" . -}}
{{- end -}}
{{- $baseurl := urls.Parse .Page.Site.BaseURL -}}
{{- $desturl := urls.Parse .Destination -}}
<a href="{{ .Destination | safeURL }}"
{{- with $parsedTitle.title }} title="{{ . }}"{{- end -}}
{{- with $parsedTitle.attributes -}}
{{- range $k, $v := . -}}
{{- printf " %s=%q" $k $v | safeHTMLAttr -}}
{{- end -}}
{{- end -}}
{{- if and (strings.HasPrefix .Destination "http") (not (strings.HasPrefix $desturl.Host $baseurl.Host)) }} target="_blank" rel="external noreferrer noopener"{{ end -}}
>{{ .Text | safeHTML }}</a>
{{- /* Strip trailing space. Code by djibe, thanks to jmooring & killbus */ -}}