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-->
|
||||
---
|
||||
|
||||
## 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 ZJthWmvUzzc >}}
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
{{- $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 $img -}}
|
||||
{{- if eq $img.MediaType.MainType "video" -}}
|
||||
<figure>
|
||||
<video class="video-shortcode" preload="metadata" controls>
|
||||
|
@ -15,6 +20,7 @@
|
|||
{{- else -}}
|
||||
<img loading="lazy" src="{{ $img.RelPermalink }}" type="" alt="{{ $.Text }}" {{ with $.Title}} title="{{ . }}" {{ end }} />
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- else -}}
|
||||
{{- warnf "No image found for %s from %s" .Destination .Page.File }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
|
Loading…
Reference in New Issue