Skip to content

Commit a659d76

Browse files
Udpated shortcode leveraging webp conversion in hugo
1 parent 2a3f966 commit a659d76

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
<figure style="text-align: center; margin: 20px 0;">
2-
<img src="{{ .Get "src" }}" alt="{{ .Get "alt" }}" style="width: {{ .Get "width" | default "80%" }}; height: auto; display: block; margin: 0 auto;" />
3-
<figcaption style="font-size: 14px; color: #666; font-style: italic; margin-top: 8px;">{{ .Inner | markdownify }}</figcaption>
4-
</figure>
2+
{{ $src := .Get "src" }}
3+
{{ $convertToWebp := .Get "webp" }}
4+
{{ if and $convertToWebp (eq $convertToWebp "true") (.Page.Resources.Get $src) }}
5+
{{ $image := .Page.Resources.Get $src }}
6+
{{ $size := .Get "size" | default "800x" }}
7+
{{ $quality := .Get "quality" | default "75" }}
8+
{{ $processed := $image.Resize (printf "%s webp q%s" $size $quality) }}
9+
<img loading="lazy" src="{{ $processed.RelPermalink }}"
10+
alt="{{ .Get "alt" }}"
11+
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
12+
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
13+
style="height: auto; display: block; margin: 0 auto;" />
14+
{{ else }}
15+
<img loading="lazy" src="{{ $src }}"
16+
alt="{{ .Get "alt" }}"
17+
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
18+
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
19+
style="height: auto; display: block; margin: 0 auto;" />
20+
{{ end }}
21+
<figcaption style="font-size: 14px; color: #666; font-style: italic; margin-top: 8px;">{{ .Inner | markdownify }}</figcaption>
22+
</figure>

0 commit comments

Comments
 (0)