aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/_default/_markup/render-image.html
blob: 00f37cffedfe4b0eea2d4256c6d2e896a2930397 (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
{{- $source      := $.Destination | safeURL -}}
{{- $localPath   := print "content/" $source -}}
{{- $remoteImage := resources.GetRemote $source -}}
{{- $width       := "" -}}
{{- $height      := "" -}}

{{- with $remoteImage -}}
  {{- with .Err -}}
    {{- if fileExists $localPath -}}
      {{- $localImage := imageConfig $localPath -}}
      {{- with $localImage -}}
        {{- $width  = .Width -}}
        {{- $height = .Height -}}
      {{- end -}}
    {{- else -}}
      {{- $source = print "/images/404.png" -}}
      {{- $localPath = print "static/" $source -}}
      {{- $localImage := imageConfig $localPath -}}
      {{- with $localImage -}}
        {{- $width  = .Width -}}
        {{- $height = .Height -}}
      {{- end -}}
    {{- end -}}
  {{- else -}}
    {{- $width  = .Width -}}
    {{- $height = .Height -}}
  {{ end }}
{{ end }}

{{- /* This comment removes trailing newlines and white spaces. */ -}}
<figure>
  <a href="{{ $source }}">
    <img loading="lazy"
      src="{{ $source }}"
      alt="{{ $.Text | htmlUnescape }}"
      title="{{ $.Text | htmlUnescape }}"
      width="{{ $width }}"
      height="{{ $height }}"
    />
  </a>
{{ if $.Title }}
  <figcaption>{{ $.Title | markdownify }}</figcaption>
{{ end -}}
</figure>
{{- /* This comment removes trailing newlines and white spaces. */ -}}