Make the link template handle abs and other domain urls

Signed-off-by: Matt Farina <matt.farina@suse.com>
This commit is contained in:
Matt Farina 2021-05-17 16:46:23 -04:00
parent 1ab43d9c2f
commit 24a09c86e7
No known key found for this signature in database
GPG Key ID: 92C44A3D421FF7F9
2 changed files with 11 additions and 1 deletions

BIN
content/blog/.DS_Store vendored

Binary file not shown.

View File

@ -1 +1,11 @@
<img src="{{ printf "%s%s" .Page.Permalink .Destination | safeURL }}" {{ with .Text }} alt="{{ . }}" {{ end }} {{ with .Title }} title="{{ . }}" {{ end }} />
{{ $dest := .Destination -}}
{{ $url := urls.Parse .Destination -}}
{{ if eq $url.Host "" -}}
{{ if hasPrefix $url.Path "/" -}}
{{ $base := strings.TrimSuffix "/" .Page.Site.BaseURL -}}
{{ $dest = printf "%s%s" $base .Destination -}}
{{ else -}}
{{ $dest = printf "%s%s" .Page.Permalink .Destination -}}
{{ end -}}
{{ end -}}
<img src="{{ $dest | safeURL }}" {{ with .Text }} alt="{{ . }}" {{ end }} {{ with .Title }} title="{{ . }}" {{ end }} />