We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent adee299 commit c9a7551Copy full SHA for c9a7551
1 file changed
layouts/shortcodes/img.html
@@ -0,0 +1,24 @@
1
+{{- $alt := .Get "alt" -}}
2
+{{- $res := resources.GetMatch (.Get "src") -}}
3
+{{- $ws := slice 480 768 1366 1920 -}}
4
+{{- $srcset := slice -}}
5
+{{- range $ws -}}
6
+{{/* to avoid creating an image that is larger than the source */}}
7
+{{- if (le . $res.Width) -}}
8
+{{- $w := printf "%dx" . -}}
9
+{{- $url := ($res.Resize $w).RelPermalink | safeURL -}}
10
+{{- $fmt := printf "%s %dw" $url . -}}
11
+{{- $srcset = $srcset | append $fmt -}}
12
+{{- end -}}
13
14
+{{- $set := delimit $srcset "," -}}
15
+<figure>
16
+ <img
17
+ srcset="{{ $set }}"
18
+ sizes="(max-width: 800px) 800px, 100vw"
19
+ src="{{ $res.RelPermalink }}"
20
+ alt="{{ $alt }}"
21
+ width="100%"
22
+ height="auto"/>
23
+ <figcaption>{{ $alt }}</figcaption>
24
+</figure>
0 commit comments