From 0935880bf3ca90ab6a44e012fa867d06d6a7a3bf Mon Sep 17 00:00:00 2001 From: Reorx Date: Sat, 3 Sep 2022 21:36:36 +0800 Subject: fix markdown image render hook, handle third party image url --- layouts/_default/_markup/render-image.html | 38 +++++++++++++++++------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'layouts/_default/_markup/render-image.html') 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 */}} + {{ $.Text }} +{{- else -}} + {{/* internal image */}} + {{- $img := .Page.Resources.GetMatch .Destination -}} + {{- if not $img -}} + {{- $img = resources.Get .Destination -}} + {{- end -}} -{{- if $img -}} - {{- if eq $img.MediaType.MainType "video" -}} -
- -
+ {{- if $img -}} + {{- if eq $img.MediaType.MainType "video" -}} +
+ +
+ {{- else -}} + {{ $.Text }} + {{- end -}} {{- else -}} - {{ $.Text }} + {{- 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 -}} -- cgit v1.2.3