fix markdown image render hook, handle third party image url
This commit is contained in:
parent
295396b440
commit
0935880bf3
Binary file not shown.
After Width: | Height: | Size: 95 KiB |
|
@ -14,6 +14,16 @@ Hugo ships with several [Built-in Shortcodes](https://gohugo.io/content-manageme
|
||||||
<!--more-->
|
<!--more-->
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Image
|
||||||
|
|
||||||
|
third party image:
|
||||||
|
|
||||||
|
![](https://images.unsplash.com/photo-1662141978148-2eeb2afb3837?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=772&q=80)
|
||||||
|
|
||||||
|
internal image:
|
||||||
|
|
||||||
|
![](images/regular.jpg)
|
||||||
|
|
||||||
## YouTube Privacy Enhanced Shortcode
|
## YouTube Privacy Enhanced Shortcode
|
||||||
|
|
||||||
{{< youtube ZJthWmvUzzc >}}
|
{{< youtube ZJthWmvUzzc >}}
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
{{- $img := .Page.Resources.GetMatch .Destination -}}
|
{{- $url := urls.Parse .Destination -}}
|
||||||
{{- if and (not $img) .Page.File -}}
|
{{- if $url.Scheme -}}
|
||||||
{{ $path := path.Join .Page.File.Dir .Destination }}
|
{{/* third party image */}}
|
||||||
{{- $img = resources.Get $path -}}
|
<img loading="lazy" src="{{ .Destination | safeURL }}" alt="{{ $.Text }}" {{ with $.Title}} title="{{ . }}" {{ end }} />
|
||||||
{{- end -}}
|
{{- else -}}
|
||||||
|
{{/* internal image */}}
|
||||||
|
{{- $img := .Page.Resources.GetMatch .Destination -}}
|
||||||
|
{{- if not $img -}}
|
||||||
|
{{- $img = resources.Get .Destination -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
{{- if $img -}}
|
{{- if $img -}}
|
||||||
{{- if eq $img.MediaType.MainType "video" -}}
|
{{- if eq $img.MediaType.MainType "video" -}}
|
||||||
<figure>
|
<figure>
|
||||||
<video class="video-shortcode" preload="metadata" controls>
|
<video class="video-shortcode" preload="metadata" controls>
|
||||||
|
@ -15,6 +20,7 @@
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
<img loading="lazy" src="{{ $img.RelPermalink }}" type="" alt="{{ $.Text }}" {{ with $.Title}} title="{{ . }}" {{ end }} />
|
<img loading="lazy" src="{{ $img.RelPermalink }}" type="" alt="{{ $.Text }}" {{ with $.Title}} title="{{ . }}" {{ end }} />
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
{{- warnf "No image found for %s from %s" .Destination .Page.File }}
|
{{- warnf "No image found for %s from %s" .Destination .Page.File }}
|
||||||
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
Loading…
Reference in New Issue