|
| 1 | +{{/* |
| 2 | + Usage: |
| 3 | + {{< figure |
| 4 | + class="specificclass" |
| 5 | + align="center" // this adds "center" to the class of the image |
| 6 | + src="sourceImage" // Image location. May be in the page bundle, in the site resources, or be external to the site (eg: https://other.site/image.png) |
| 7 | + link="targetOfTheImageLink" // Makes the image into a link |
| 8 | + linkFullImage="false // If link is NOT provided, AND this parameter is "true", |
| 9 | + // then makes the image into a link to the full size image |
| 10 | + responsive="false" // If the image is found in the page bundle or in the site resources |
| 11 | + // AND if the environment is "production" |
| 12 | + // AND if the image is in a processable format |
| 13 | + // AND if this parameter is "true", then smaller images are created, |
| 14 | + // responsiveness is provided by way of srcset, the browser chooses the image size |
| 15 | + title="Title of the image" |
| 16 | + alt="Alternative text" |
| 17 | + caption="Text to appear below the image" |
| 18 | + attr="End text of the caption" |
| 19 | + attrlink="targetURLForAttr" // If provided, turns the end text of the caption into a link |
| 20 | + >}} |
| 21 | +*/}} |
1 | 22 | <figure{{ if or (.Get "class") (eq (.Get "align") "center") }} class=" |
2 | 23 | {{- if eq (.Get "align") "center" }}align-center {{ end }} |
3 | 24 | {{- with .Get "class" }}{{ . }}{{- end }}" |
|
9 | 30 | {{- $processableFormats = $processableFormats | append "webp" -}} |
10 | 31 | {{- end -}} |
11 | 32 |
|
| 33 | + {{- /* Find the image in the page bundle or in the site resources */ -}} |
12 | 34 | {{- $image := "" -}} |
13 | | - {{- if $.Page.Resources -}} |
14 | | - {{- $image = $.Page.Resources.Get (.Get "src") -}} |
| 35 | + {{- $imageURL := urls.Parse (.Get "src") -}} |
| 36 | + {{- $imageSrc := $imageURL.String -}} |
| 37 | + {{- if not $imageURL.IsAbs -}} |
| 38 | + {{- $image = or (.Page.Resources.Get $imageURL.Path) (resources.Get $imageURL.Path) -}} |
| 39 | + {{- $imageSrc = $image.RelPermalink -}} |
15 | 40 | {{- end -}} |
16 | | - {{- if not $image -}} |
17 | | - {{- $image = resources.Get (.Get "src") -}} |
18 | | - {{- end -}} |
19 | | - {{- $imageSrc := $image.RelPermalink | default ( .Get "src" ) -}} |
20 | 41 |
|
| 42 | + {{/* Make the image into a link, provided by the developer, or a link into itself in its original size */}} |
21 | 43 | {{- $linkURL := .Get "link" -}} |
22 | 44 | {{- $linkFullImage := .Get "linkFullImage" | default "false" | eq "true" -}} |
23 | 45 | {{- if and $linkFullImage (not $linkURL) $image -}} |
24 | 46 | {{- $linkURL = $image.RelPermalink -}} |
25 | 47 | {{- end -}} |
26 | 48 |
|
27 | | - {{- $responsive := .Get "responsive" | default "false" | eq "true" -}} |
28 | | - |
29 | | - {{- $responsive = and $prod $image $responsive ( in $processableFormats $image.MediaType.SubType ) -}} |
30 | | - |
31 | 49 | {{- if $linkURL -}} |
32 | 50 | <a href="{{ $linkURL }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}> |
33 | 51 | {{- end }} |
34 | 52 |
|
| 53 | + {{- $responsive := .Get "responsive" | default "false" | eq "true" -}} |
| 54 | + {{- $responsive = and $prod $image $responsive ( in $processableFormats $image.MediaType.SubType ) -}} |
| 55 | + |
35 | 56 | {{- if $responsive }} |
36 | | - {{- $sizes := (slice "360" "480" "720" "1080" "1500") }} |
| 57 | + {{- $sizes := (slice "360" "480" "720" "1080" "1500") }} |
37 | 58 | <img loading="lazy" |
38 | 59 | srcset='{{- range $size := $sizes -}} |
39 | 60 | {{- if (ge $image.Width (int $size)) }} |
|
0 commit comments