Have external links open in a new tab

Usually when linking to outside sources, I find myself wanting to do so in a new tab. Internal links will continue to route in the current tab.
This commit is contained in:
Brandon Boswell 2022-05-11 22:42:58 -04:00 committed by GitHub
parent ed9a8efd1f
commit 2c6f847d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@
{{$dashedurl := replace $trimmed "%20" "-" }}
{{$external := strings.HasPrefix $dashedurl "http" }}
{{- if $external -}}
<a href="{{ $dashedurl }}" rel="noopener">{{ .Text | safeHTML }}</a>
<a target="_blank" href="{{ $dashedurl }}" rel="noopener">{{ .Text | safeHTML }}</a>
{{- else -}}
{{$spacedurl := replace $trimmed "%20" " " }}
{{$fixedUrl := (cond (hasPrefix $spacedurl "/") $spacedurl (print "/" $spacedurl)) | urlize}}