diff options
| author | tdro <tdro@noreply.example.com> | 2024-09-09 00:00:00 +0000 |
|---|---|---|
| committer | tdro <tdro@noreply.example.com> | 2024-09-09 00:00:00 +0000 |
| commit | 204ac1bfe954433ca1be87be23f2e27e544f6ebd (patch) | |
| tree | d10042e7d98b86a36273591a3363eb6575f037a5 | |
| parent | 09cfe9bd7cd131773dfe3a913e1ad08fb16cd786 (diff) | |
| download | canory-204ac1bfe954433ca1be87be23f2e27e544f6ebd.tar.gz canory-204ac1bfe954433ca1be87be23f2e27e544f6ebd.tar.bz2 canory-204ac1bfe954433ca1be87be23f2e27e544f6ebd.zip | |
themes/default/layouts/_default/_markup/render-link: Handle protocol relative links
| -rw-r--r-- | themes/default/layouts/_default/_markup/render-link.html | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/themes/default/layouts/_default/_markup/render-link.html b/themes/default/layouts/_default/_markup/render-link.html index ccfbc06..44cd8a3 100644 --- a/themes/default/layouts/_default/_markup/render-link.html +++ b/themes/default/layouts/_default/_markup/render-link.html @@ -1,21 +1,20 @@ -{{- $link := .Destination -}} -{{- $url := urls.Parse $link -}} -{{- $site := urls.Parse .Page.Site.BaseURL -}} -{{- $local := or (eq $url.Host $site.Host) (strings.HasPrefix $link "/") -}} +{{- $link := .Destination -}} +{{- $target := urls.Parse $link -}} +{{- $self := urls.Parse .Page.Site.BaseURL -}} +{{- $prurl := eq (findRE `^/\w` $link | len) 0 -}} +{{- $local := or (eq $target.Host $self.Host) (and (strings.HasPrefix $link "/") (not $prurl)) -}} {{- $remote := not $local -}} -{{- if and $local $url.Path -}} +{{- if and $local $target.Path -}} + {{- $fragment := "" -}} -{{- $fragment := "" -}} - - {{- with $url.Fragment -}} + {{- with $target.Fragment -}} {{- $fragment = printf "#%s" . -}} {{- end -}} - {{- with .Page.GetPage $url.Path -}} + {{- with .Page.GetPage $target.Path -}} {{- $link = printf "%s%s" .Permalink $fragment -}} {{- end -}} - {{- end -}} <a |
