summaryrefslogtreecommitdiff
path: root/layouts/shortcodes/img-center.html
blob: cca73f23433256efcebc83b0a1cf94052bae689a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{{- $file := .Get 0 }}
{{- $path := printf "content_images/%s" $file}}
{{- $img := resources.Get $path }}
{{- $caption := .Get 1 }}
{{- $source := .Get 2 }}
{{- $img1x := $img.Resize "800x jpg q90"}}
{{- $img2x := $img.Resize "1600x jpg q90"}}
<figure>
  <img
    loading="lazy"
    class="center"
    alt="{{ $caption }}" 
    src="{{ $img1x.Permalink }}" 
    srcset="
            {{ $img1x.Permalink }} 1x,
            {{ $img2x.Permalink }} 2x
            "
    width="{{ $img1x.Width }}" 
    height="{{ $img1x.Height }}"
    >
  <figcaption>
    {{ $caption }}

    {{- if $source }}
    <a href="{{ $source }}" target="_blank" title="source">[source]</a>
    {{ end }}
  </figcaption>
</figure>