fix(markdown image): be able to insert external images

This commit is contained in:
Jimmy Cai 2020-08-22 21:02:30 +02:00
parent 35ce4cb0ce
commit d36a7c0950

View File

@ -1,12 +1,13 @@
{{- $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 -}}
<figure>
<a href="{{ $image.RelPermalink }}" data-size="{{ $image.Width }}x{{ $image.Height }}"> <a href="{{ $image.RelPermalink }}" data-size="{{ $image.Width }}x{{ $image.Height }}">
<img srcset="{{ $small.RelPermalink }} 480w, {{ $big.RelPermalink }} 1024w" <img srcset="{{ $small.RelPermalink }} 480w, {{ $big.RelPermalink }} 1024w"
src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" loading="lazy" src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" loading="lazy"
@ -15,4 +16,7 @@
{{ with $caption }} {{ with $caption }}
<figcaption>{{ . | markdownify }}</figcaption> <figcaption>{{ . | markdownify }}</figcaption>
{{ end }} {{ end }}
</figure> </figure>
{{- else -}}
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title }} title="{{ . }}"{{ end }} />
{{- end -}}