blob: b99d3d5e770156f20f29a874b72581ff9f0be462 (
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
<!--
Usage:
img "weird_cat.jpg" "Something that can (or not) be a cat."
img src="weird_cat.jpg" alt="Something that can (or not) be a cat."
img class="border" src="weird_cat.jpg" alt="Something that can (or not) be a cat." resize=false
img "weird_cat.jpg" "Something that can (or not) be a cat." "border" false
Default available classes:
border
borderless
-->
{{ $file := .Get "src" | default (.Get 0) }}
{{ $caption := (.Get "caption" | default (.Get 1)) | markdownify }}
{{ $class := .Get "class" | default (.Get 2) }}
{{ $resize := .Get "resize" | default (.Get 3) }}
{{ $altText := .Get "alt" | default $caption }}
{{ $destination := $file }}
<!-- Image processing configuration -->
{{ $imgProcConfig := partialCached "utilities/image-processing-config" . }}
<!-- Default image path -->
{{ $imgPath := .Page.Param "imgPath" }}
{{ if $imgPath }}
{{ $file = path.Join $imgPath $file }}
{{ end }}
{{ $inputFile := .Page.Resources.GetMatch $file }}
{{ with partial "utilities/image-processing" (dict "context" . "input" $inputFile "resize" $resize "config" $imgProcConfig) }}
{{ if .sets.default }}
<figure>
<picture>
<!-- Extra sets -->
{{ range .sets.extra }}
<source
srcset='{{ delimit .source ", " }}'
type="{{ .mediaType }}"
>
{{ end }}
<!-- Default set -->
<source
srcset='{{ delimit .sets.default ", " }}'
type="{{ .default.MediaType }}"
>
<img
{{ with $class }}class="{{ . }}"{{ end }}
loading="lazy"
{{ with .default }}
src="{{ .RelPermalink }}"
width="{{ .Width }}"
height="{{ .Height }}"
{{ end }}
{{ with $altText }}alt="{{ . }}"{{ end }}
>
</picture>
{{ with $caption }}
<figcaption>{{ . }}</figcaption>
{{ end }}
</figure>
{{ else }}
<!-- Avoid trying to get width and height from SVG files -->
{{ if .input }}
<figure>
<img
{{ with $class }}class="{{ . }}"{{ end }}
loading="lazy"
{{ with .input }}
src="{{ .RelPermalink }}"
{{ if ne .MediaType.SubType "svg" }}
width="{{ .Width }}"
height="{{ .Height }}"
{{ end }}
{{ end }}
{{ with $altText }}alt="{{ . }}"{{ end }}
>
{{ with $caption }}
<figcaption>{{ . }}</figcaption>
{{ end }}
</figure>
{{ else }}
<!-- If local file isn't found, assume it's a remote file -->
{{ with ($destination | safeURL) }}
<figure>
<img
{{ with $class }}class="{{ . }}"{{ end }}
loading="lazy"
src="{{ . }}"
{{ with $altText }}alt="{{ . }}"{{ end }}
>
{{ with $caption }}
<figcaption>{{ . }}</figcaption>
{{ end }}
</figure>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
|