aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/_default/_markup/render-image.html
blob: b588842f6e84f30c82a10a52898f7b4464f872b1 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{{- $source     := $.Destination | safeURL -}}
{{- $public     := print "public/" $source -}}
{{- $remote     := resources.GetRemote $source -}}
{{- $local      := "" -}}
{{- $width      := "" -}}
{{- $height     := "" -}}
{{- $cache      := "" -}}
{{- $dimensions := "600x360" -}}
{{- $immutable  := print (.Page.RelPermalink | humanize | urlize) "-" ($source | sha256 | truncate 8 "") -}}

{{- with $remote -}}
  {{- with .Err -}}
    {{- if fileExists $public -}}
      {{- $local = resources.Get $public -}}
      {{- with $local -}}
        {{- $local = .Content | resources.FromString (print (partial "function-paths-media.html") "/" $.Page.Section "/" (path.Base .)) -}}
      {{- end -}}
      {{ $source = print ("" | absURL) $source }}
    {{- else -}}
      {{- $404image := resources.Get "data/media/404.png" -}}
      {{- with $404image -}}
        {{- $width  = .Width -}}
        {{- $height = .Height -}}
      {{- end -}}
      {{ $source = $404image.RelPermalink }}
    {{- end -}}
  {{- else -}}
    {{- $cache = .Content | resources.FromString (print (partial "function-paths-media.html") "/" $.Page.Section "/" (path.Base .)) -}}
  {{ end }}
{{ end }}
{{- /* This comment removes trailing newlines and white spaces. */ -}}
<figure>
  <a href="{{ $source }}">
    <picture>
      {{- with $local }}
        {{- $local = .Fit (print $dimensions " webp") }}
        {{- $local = $local | resources.Copy (print (partial "function-paths-media.html") "/" $.Page.Section "/" $immutable ".webp") }}
        <source srcset="{{- $local.RelPermalink -}}" type="image/webp" />
        {{- $local = .Fit $dimensions }}
        {{- $local = $local | resources.Copy (print (partial "function-paths-media.html") "/" $.Page.Section "/" $immutable (path.Ext $local)) }}
        {{- $width = $local.Width -}}
        {{- $height = $local.Height -}}
        {{- $writeToFile := $local.Permalink }}
      {{- end }}
      {{- with $cache }}
        {{- $cache = .Fit (print $dimensions " webp") }}
        {{- $cache = $cache | resources.Copy (print $.Page.Section "/media/" $immutable ".webp") }}
        <source srcset="{{- $cache.RelPermalink -}}" type="image/webp" />
        {{- $cache = .Fit $dimensions }}
        {{- $cache = $cache | resources.Copy (print (partial "function-paths-media.html") "/" $.Page.Section "/" $immutable (path.Ext $cache)) }}
        {{- $width = $cache.Width -}}
        {{- $height = $cache.Height -}}
        {{- $cache = $cache.RelPermalink }}
      {{- end }}
      <img loading="lazy"
        src="{{ or $cache $source }}"
        alt="{{ $.Text | htmlUnescape }}"
        title="{{ $.Text | htmlUnescape }}"
        width="{{ $width }}"
        height="{{ $height }}"
      />
    </picture>
  </a>
  <figcaption>
  {{ with $.Title -}}
    {{ . | markdownify }}
  {{ else -}}
    Image/Picture
  {{ end -}}
  <br>
  Index: {{ with $cache }} {{ print "[Cache](" . ")" | markdownify }} &middot; {{ end }}
  {{ print "[Source](" $source ")" | markdownify }}
  </figcaption>
</figure>
{{- /* This comment removes trailing newlines and white spaces. */ -}}