|
3 | 3 | {{- $resources := .Resources.ByType "image" -}} |
4 | 4 | {{/* Find featured image resources if the images parameter is empty. */}} |
5 | 5 | {{- if not $imgParams }} |
6 | | - {{- $featured := $resources.GetMatch "*feature*" -}} |
7 | | - {{- if not $featured }}{{ $featured = $resources.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} |
8 | | - {{- with $featured }} |
9 | | - {{- $imgs = $imgs | append (dict |
10 | | - "Image" . |
11 | | - "RelPermalink" .RelPermalink |
12 | | - "Permalink" .Permalink) }} |
13 | | - {{- end }} |
| 6 | + {{- $featured := $resources.GetMatch "*feature*" -}} |
| 7 | + {{- if not $featured }}{{ $featured = $resources.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} |
| 8 | + {{- with $featured }} |
| 9 | + {{- $imgs = $imgs | append (dict |
| 10 | + "Image" . |
| 11 | + "RelPermalink" .RelPermalink |
| 12 | + "Permalink" .Permalink |
| 13 | + ) |
| 14 | + }} |
| 15 | + {{- end }} |
14 | 16 | {{- end }} |
15 | 17 | {{/* Use the first one of site images as the fallback. */}} |
16 | 18 | {{- if and (not $imgParams) (not $imgs) }} |
17 | | - {{- with site.Params.images }} |
18 | | - {{- $imgParams = first 1 . }} |
19 | | - {{- end }} |
| 19 | + {{- with site.Params.images }} |
| 20 | + {{- $imgParams = first 1 . }} |
| 21 | + {{- end }} |
20 | 22 | {{- end }} |
21 | 23 | {{/* Parse page's images parameter. */}} |
22 | 24 | {{- range $imgParams }} |
23 | | - {{- $img := . }} |
24 | | - {{- $url := urls.Parse $img }} |
25 | | - {{- if eq $url.Scheme "" }} |
26 | | - {{/* Internal image: check page resources first, then global resources. */}} |
27 | | - {{- with or ($resources.GetMatch $img) (resources.GetMatch $img) -}} |
28 | | - {{- $imgs = $imgs | append (dict |
29 | | - "Image" . |
30 | | - "RelPermalink" .RelPermalink |
31 | | - "Permalink" .Permalink) }} |
32 | | - {{- else }} |
33 | | - {{- $imgs = $imgs | append (dict |
34 | | - "RelPermalink" (relURL $img) |
35 | | - "Permalink" (absURL $img) |
36 | | - ) }} |
37 | | - {{- end }} |
38 | | - {{- else }} |
39 | | - {{/* External image */}} |
40 | | - {{- $imgs = $imgs | append (dict |
41 | | - "RelPermalink" $img |
42 | | - "Permalink" $img |
43 | | - ) }} |
44 | | - {{- end }} |
| 25 | + {{- $img := . }} |
| 26 | + {{- $url := urls.Parse $img }} |
| 27 | + {{- if eq $url.Scheme "" }} |
| 28 | + {{/* Internal image: check page resources first, then global resources. */}} |
| 29 | + {{- with or ($resources.GetMatch $img) (resources.GetMatch $img) -}} |
| 30 | + {{- $imgs = $imgs | append (dict |
| 31 | + "Image" . |
| 32 | + "RelPermalink" .RelPermalink |
| 33 | + "Permalink" .Permalink |
| 34 | + ) |
| 35 | + }} |
| 36 | + {{- else }} |
| 37 | + {{- $imgs = $imgs | append (dict |
| 38 | + "RelPermalink" (relURL $img) |
| 39 | + "Permalink" (absURL $img) |
| 40 | + ) |
| 41 | + }} |
| 42 | + {{- end }} |
| 43 | + {{- else }} |
| 44 | + {{/* External image */}} |
| 45 | + {{- $imgs = $imgs | append (dict |
| 46 | + "RelPermalink" $img |
| 47 | + "Permalink" $img |
| 48 | + ) |
| 49 | + }} |
| 50 | + {{- end }} |
45 | 51 | {{- end }} |
46 | 52 | {{- return $imgs }} |
0 commit comments