1
+ {{- $file := .Destination -}}
2
+ {{- $imagesDir := .Page.Site.Params.imagesDir -}}
3
+ {{- $alt := .Text -}}
4
+ {{- $cap := .Title -}}
5
+ {{- $scratch := newScratch -}}
6
+ {{- $scratch.Set "classes" "image_figure" -}}
7
+
8
+ {{/* Determine if page bundles are set. */}}
9
+ {{- $bundle := .Page.Site.Params.usePageBundles -}}
10
+ {{- if eq .Page.Params.usePageBundles false -}}
11
+ {{- $bundle = false -}}
12
+ {{- end -}}
13
+ {{- if eq .Page.Params.usePageBundles true -}}
14
+ {{- $bundle = true -}}
15
+ {{- end -}}
16
+
17
+ {{/* Determine source of image and get attributes. */}}
18
+ {{- $image := "" -}}
19
+ {{- if strings.HasPrefix $file "http" -}}
20
+ {{- $scratch.Add "classes" " image_external" -}}
21
+ {{- $image = resources.GetRemote $file -}}
22
+ {{- with $image }}
23
+ {{- if eq $image.MediaType.MainType "image" -}}
24
+ {{- if eq $image.MediaType.SubType "svg" -}}
25
+ {{- $image = "" -}}
26
+ {{- $scratch.Add "classes" " image_svg" -}}
27
+ {{- else -}}
28
+ {{- $file = path.Join $imagesDir $image -}}
29
+ {{- $image = $image.Content | resources.FromString $file -}}
30
+ {{- end -}}
31
+ {{- else -}}
32
+ {{- $image = "" -}}
33
+ {{- end -}}
34
+ {{- end -}}
35
+ {{- else -}}
36
+ {{- $scratch.Add "classes" " image_internal" -}}
37
+ {{ $file = (path.Clean $file) }}
38
+ {{- if eq $bundle true -}}
39
+ {{ $image = .Page.Resources.GetMatch $file }}
40
+ {{- if and (not $image) .Page.File -}}
41
+ {{ $file = path.Join .Page.RelPermalink $file }}
42
+ {{ $image = resources.Get $file }}
43
+ {{- end -}}
44
+ {{- end -}}
45
+ {{- end -}}
46
+
47
+ {{ with $.Page.File }}
48
+ {{- partial "figure" (
49
+ dict
50
+ "file" $file
51
+ "image" $image
52
+ "diskPath" $.Page.File.Dir
53
+ "webPath" $.Page.RelPermalink
54
+ "alt" $alt
55
+ "cap" $cap
56
+ "classes" ($scratch.Get "classes")
57
+ "bundle" $bundle
58
+ ) -}}
59
+ {{ end }}
0 commit comments