| 1 |
{{- $imgs := slice }} |
| 2 |
{{- $imgParams := .Params.images }} |
| 3 |
{{- $resources := .Resources.ByType "image" -}} |
| 4 |
{{/* Find featured image resources if the images parameter is empty. */}} |
| 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 |
) |
| 14 |
}} |
| 15 |
{{- end }} |
| 16 |
{{- end }} |
| 17 |
{{/* Use the first one of site images as the fallback. */}} |
| 18 |
{{- if and (not $imgParams) (not $imgs) }} |
| 19 |
{{- with site.Params.images }} |
| 20 |
{{- $imgParams = first 1 . }} |
| 21 |
{{- end }} |
| 22 |
{{- end }} |
| 23 |
{{/* Parse page's images parameter. */}} |
| 24 |
{{- range $imgParams }} |
| 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 }} |
| 51 |
{{- end }} |
| 52 |
{{- return $imgs }} |