I am trying to adapt the embedded link render hook to open external links (links that point to outside the current website) in a new tab. Here is what I got,
<!-- https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_markup/render-link.html -->
{{- $u := urls.Parse .Destination -}}
{{- $href := $u.String -}}
{{- $external := false -}}
{{- if strings.HasPrefix $u.String "#" -}}
{{- $href = printf "%s#%s" .PageInner.RelPermalink $u.Fragment -}}
{{- else if strings.HasPrefix $u.String "http" -}}
{{- $external = true -}}
{{- else if and $href (not $u.IsAbs) -}}
{{- $path := strings.TrimPrefix "./" $u.Path -}}
{{- with or
($.PageInner.GetPage $path)
($.PageInner.Resources.Get $path)
(resources.Get $path)
-}}
{{- $href = .RelPermalink -}}
{{- with $u.RawQuery -}}
{{- $href = printf "%s?%s" $href . -}}
{{- end -}}
{{- with $u.Fragment -}}
{{- $href = printf "%s#%s" $href . -}}
{{- end -}}
{{- end -}}
{{- end -}}
<a
href="{{ $href }}"
{{- with .Title }}
title="{{ . }}"
{{- end }}
{{- with $external }}
target="_blank"
rel="noopener noreferrer"
{{- end }}
>
{{ .Text }}
</a>
{{- /**/ -}}
Does this look okay? Or–have I missed something important?