Skip to content

Commit c9a7551

Browse files
committed
probably wont fix but just incase
1 parent adee299 commit c9a7551

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

layouts/shortcodes/img.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
{{- end -}}
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

Comments
 (0)