Open external links in new tab

rust
Elnu 3 years ago
parent 427f42dde3
commit ab3df7a361

@ -0,0 +1,16 @@
<!-- https://github.com/bep/hugo-mod-misc/blob/79a51b35c8cd162bc9977aba0c07bd0e93f69d25/render-hooks/layouts/_default/_markup/render-link.html -->
{{ $link := .Destination }}
{{ $isRemote := strings.HasPrefix $link "http" }}
{{- if not $isRemote -}}
{{ $url := urls.Parse .Destination }}
{{- if $url.Path -}}
{{ $fragment := "" }}
{{- with $url.Fragment }}
{{ $fragment = printf "#%s" . }}
{{ end -}}
{{- with .Page.GetPage $url.Path }}
{{ $link = printf "%s%s" .RelPermalink $fragment }}
{{ end }}
{{ end -}}
{{- end -}}
<a href="{{ $link | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isRemote }} target="_blank"{{ end }}>{{ .Text | safeHTML }}</a>
Loading…
Cancel
Save