aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/_default/_markup/render-image.html
blob: 1b73563163bfc5aa0157f3bba198bfecb010f13e (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
{{- $source      := $.Destination | safeURL -}}
{{- $public      := print "public/" $source -}}
{{- $remoteImage := resources.GetRemote $source -}}
{{- $dimensions  := "600x" -}}
{{- $width       := "" -}}
{{- $height      := "" -}}
{{- $sourceFit   := "" -}}

{{- with $remoteImage -}}
  {{- with .Err -}}
    {{- if fileExists $public -}}
      {{- $localImage := imageConfig $public -}}
      {{- with $localImage -}}
        {{- $width  = .Width -}}
        {{- $height = .Height -}}
      {{- end -}}
      {{ $source = print ("" | absURL) $source }}
    {{- else -}}
      {{- $source = print "/images/404.png" -}}
      {{- $404image := imageConfig (print "static/" $source) -}}
      {{- with $404image -}}
        {{- $width  = .Width -}}
        {{- $height = .Height -}}
      {{- end -}}
      {{ $source = print ("" | absURL) $source }}
    {{- end -}}
  {{- else -}}
    {{- $width  = .Width -}}
    {{- $height = .Height -}}
    {{- $sourceFit = (.Resize $dimensions).Permalink -}}
  {{ end }}
{{ end }}

{{- /* This comment removes trailing newlines and white spaces. */ -}}
<figure>
  <a href="{{ $source }}">
    <img loading="lazy"
      src="{{ or $sourceFit $source }}"
      alt="{{ $.Text | htmlUnescape }}"
      title="{{ $.Text | htmlUnescape }}"
      width="{{ $width }}"
      height="{{ $height }}"
    />
  </a>
  <figcaption>
  {{ with $.Title -}}
    {{ . | markdownify }}
  {{ else -}}
    Image/Picture
  {{ end -}}
  <br>
  {{ with $sourceFit }} Cache: {{ print "[Link](" . ")" | markdownify }} &middot; {{ end }}
  Source: {{ print "[Link](" $source ")" | markdownify }}
  </figcaption>
</figure>
{{- /* This comment removes trailing newlines and white spaces. */ -}}