mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2024-11-27 04:03:48 +01:00
fix(markdown image): be able to insert external images
This commit is contained in:
parent
35ce4cb0ce
commit
d36a7c0950
1 changed files with 21 additions and 17 deletions
|
@ -1,18 +1,22 @@
|
||||||
{{- $image := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) -}}
|
{{- $image := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) -}}
|
||||||
{{- $small := $image.Resize "480x" -}}
|
{{- if $image -}}
|
||||||
{{- $big := $image.Resize "1024x" -}}
|
{{- $small := $image.Resize "480x" -}}
|
||||||
{{- $alt := .PlainText | safeHTML -}}
|
{{- $big := $image.Resize "1024x" -}}
|
||||||
{{- $caption := "" -}}
|
{{- $alt := .PlainText | safeHTML -}}
|
||||||
{{- with $alt -}}
|
{{- $caption := "" -}}
|
||||||
{{- $caption = . | safeHTML -}}
|
{{- with $alt -}}
|
||||||
{{- end -}}
|
{{- $caption = . | safeHTML -}}
|
||||||
<figure>
|
{{- end -}}
|
||||||
<a href="{{ $image.RelPermalink }}" data-size="{{ $image.Width }}x{{ $image.Height }}">
|
<figure>
|
||||||
<img srcset="{{ $small.RelPermalink }} 480w, {{ $big.RelPermalink }} 1024w"
|
<a href="{{ $image.RelPermalink }}" data-size="{{ $image.Width }}x{{ $image.Height }}">
|
||||||
src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" loading="lazy"
|
<img srcset="{{ $small.RelPermalink }} 480w, {{ $big.RelPermalink }} 1024w"
|
||||||
alt="{{ if $alt }}{{ $alt }}{{ else if $caption }}{{ $caption | markdownify | plainify }}{{ else }} {{ end }}">
|
src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" loading="lazy"
|
||||||
</a>
|
alt="{{ if $alt }}{{ $alt }}{{ else if $caption }}{{ $caption | markdownify | plainify }}{{ else }} {{ end }}">
|
||||||
{{ with $caption }}
|
</a>
|
||||||
<figcaption>{{ . | markdownify }}</figcaption>
|
{{ with $caption }}
|
||||||
{{ end }}
|
<figcaption>{{ . | markdownify }}</figcaption>
|
||||||
</figure>
|
{{ end }}
|
||||||
|
</figure>
|
||||||
|
{{- else -}}
|
||||||
|
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }} title="{{ . }}"{{ end }} />
|
||||||
|
{{- end -}}
|
Loading…
Reference in a new issue