diff options
| author | Reorx <novoreorx@gmail.com> | 2022-09-03 21:36:36 +0800 |
|---|---|---|
| committer | Reorx <novoreorx@gmail.com> | 2022-09-03 21:36:36 +0800 |
| commit | 0935880bf3ca90ab6a44e012fa867d06d6a7a3bf (patch) | |
| tree | 0e5c13a9d9b4211c8a435791c63e59bdafe6dad4 | |
| parent | 295396b44009b6dc29c1ddfb547218d786593fcd (diff) | |
fix markdown image render hook, handle third party image url
| -rw-r--r-- | exampleSite/assets/images/regular.jpg | bin | 0 -> 97512 bytes | |||
| -rw-r--r-- | exampleSite/content/posts/rich-content.md | 10 | ||||
| -rw-r--r-- | layouts/_default/_markup/render-image.html | 38 |
3 files changed, 32 insertions, 16 deletions
diff --git a/exampleSite/assets/images/regular.jpg b/exampleSite/assets/images/regular.jpg Binary files differnew file mode 100644 index 0000000..70a3401 --- /dev/null +++ b/exampleSite/assets/images/regular.jpg diff --git a/exampleSite/content/posts/rich-content.md b/exampleSite/content/posts/rich-content.md index b7c896a..81fac33 100644 --- a/exampleSite/content/posts/rich-content.md +++ b/exampleSite/content/posts/rich-content.md @@ -14,6 +14,16 @@ Hugo ships with several [Built-in Shortcodes](https://gohugo.io/content-manageme <!--more--> --- +## Image + +third party image: + + + +internal image: + + + ## YouTube Privacy Enhanced Shortcode {{< youtube ZJthWmvUzzc >}} 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 -}} |
