aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/_default
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2022-11-17 16:16:44 -0500
committertdro <tdro@noreply.example.com>2022-11-17 16:16:44 -0500
commita0d023cfe24150a1130ff8638ba5ef845da156de (patch)
treecbdd3ce1b4f3e13c7705fb6c0948c8351a71c14e /themes/default/layouts/_default
parent688d6b044700ef1cdbb6852d288f775a38c9320c (diff)
downloadcanory-a0d023cfe24150a1130ff8638ba5ef845da156de.tar.gz
canory-a0d023cfe24150a1130ff8638ba5ef845da156de.tar.bz2
canory-a0d023cfe24150a1130ff8638ba5ef845da156de.zip
themes/default/layouts/_default/_markup/render-link: Refine remote check
Diffstat (limited to 'themes/default/layouts/_default')
-rw-r--r--themes/default/layouts/_default/_markup/render-link.html27
1 files changed, 19 insertions, 8 deletions
diff --git a/themes/default/layouts/_default/_markup/render-link.html b/themes/default/layouts/_default/_markup/render-link.html
index 8f51a57..0eaa9bd 100644
--- a/themes/default/layouts/_default/_markup/render-link.html
+++ b/themes/default/layouts/_default/_markup/render-link.html
@@ -1,17 +1,28 @@
{{- $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" .Permalink $fragment }}{{ end }}{{ end -}}
+{{- $url := urls.Parse $link -}}
+{{- $site := urls.Parse .Page.Site.BaseURL -}}
+{{- $local := or (eq $url.Host $site.Host) (strings.HasPrefix $link "/") -}}
+{{- $remote := not $local -}}
+
+{{- if and $local $url.Path -}}
+
+{{- $fragment := "" -}}
+
+ {{- with $url.Fragment -}}
+ {{- $fragment = printf "#%s" . -}}
+ {{- end -}}
+
+ {{- with .Page.GetPage $url.Path -}}
+ {{- $link = printf "%s%s" .Permalink $fragment -}}
+ {{- end -}}
+
{{- end -}}
+
<a href="{{ $link | safeURL }}"
{{ with or .Title ($link | safeURL) -}}
title="{{ . }}"
{{ end }}
- {{- if $isRemote -}}
+ {{- if $remote -}}
data-external
rel="noopener no-referrer"
{{ end }}>{{- .Text | safeHTML -}}</a>