summaryrefslogtreecommitdiff
path: root/layouts/_default/_markup/render-image.html
diff options
context:
space:
mode:
authorReorx <novoreorx@gmail.com>2022-09-03 21:36:36 +0800
committerReorx <novoreorx@gmail.com>2022-09-03 21:36:36 +0800
commit0935880bf3ca90ab6a44e012fa867d06d6a7a3bf (patch)
tree0e5c13a9d9b4211c8a435791c63e59bdafe6dad4 /layouts/_default/_markup/render-image.html
parent295396b44009b6dc29c1ddfb547218d786593fcd (diff)
fix markdown image render hook, handle third party image url
Diffstat (limited to 'layouts/_default/_markup/render-image.html')
-rw-r--r--layouts/_default/_markup/render-image.html38
1 files changed, 22 insertions, 16 deletions
diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html
index 0fc039c..c4d7497 100644
--- a/layouts/_default/_markup/render-image.html
+++ b/layouts/_default/_markup/render-image.html
@@ -1,20 +1,26 @@
-{{- $img := .Page.Resources.GetMatch .Destination -}}
-{{- if and (not $img) .Page.File -}}
- {{ $path := path.Join .Page.File.Dir .Destination }}
- {{- $img = resources.Get $path -}}
-{{- end -}}
+{{- $url := urls.Parse .Destination -}}
+{{- if $url.Scheme -}}
+ {{/* third party image */}}
+ <img loading="lazy" src="{{ .Destination | safeURL }}" alt="{{ $.Text }}" {{ with $.Title}} title="{{ . }}" {{ end }} />
+{{- else -}}
+ {{/* internal image */}}
+ {{- $img := .Page.Resources.GetMatch .Destination -}}
+ {{- if not $img -}}
+ {{- $img = resources.Get .Destination -}}
+ {{- end -}}
-{{- if $img -}}
- {{- if eq $img.MediaType.MainType "video" -}}
- <figure>
- <video class="video-shortcode" preload="metadata" controls>
- <source src="{{ $img.RelPermalink }}">
- There should have been a video here but your browser does not seem to support it.
- </video>
- </figure>
+ {{- if $img -}}
+ {{- if eq $img.MediaType.MainType "video" -}}
+ <figure>
+ <video class="video-shortcode" preload="metadata" controls>
+ <source src="{{ $img.RelPermalink }}">
+ There should have been a video here but your browser does not seem to support it.
+ </video>
+ </figure>
+ {{- else -}}
+ <img loading="lazy" src="{{ $img.RelPermalink }}" type="" alt="{{ $.Text }}" {{ with $.Title}} title="{{ . }}" {{ end }} />
+ {{- end -}}
{{- else -}}
- <img loading="lazy" src="{{ $img.RelPermalink }}" type="" alt="{{ $.Text }}" {{ with $.Title}} title="{{ . }}" {{ end }} />
+ {{- warnf "No image found for %s from %s" .Destination .Page.File }}
{{- end -}}
-{{- else -}}
- {{- warnf "No image found for %s from %s" .Destination .Page.File }}
{{- end -}}