summaryrefslogtreecommitdiff
path: root/themes/neonxp/layouts/shortcodes/img.html
blob: 994e30f441d081cb44e66eb19eee9942f753098c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{{- $alt := .Get "alt" -}}
{{- $res := .Page.Resources.Get (.Get "src") -}}

{{- $ws := slice 480 800 -}}
{{- $srcset := slice -}}
{{- range $ws -}}
{{- if (le . $res.Width) -}}
{{- $w := printf "%dx" . -}}
{{- $url := ($res.Resize $w).RelPermalink | safeURL -}}
{{- $fmt := printf "%s %dw" $url . -}}
{{- $srcset = $srcset | append $fmt -}}
{{- end -}}
{{- end -}}

{{- $set := delimit $srcset "," -}}

<figure>
    <img srcset="{{ $set }}" sizes="(max-width: 480px) 480px, 100vw" src="{{ $res.RelPermalink }}" alt="{{ $alt }}"
        height="auto" />
    <figcaption>{{ $alt }}</figcaption>
</figure>