summaryrefslogtreecommitdiff
path: root/themes/PaperMod/layouts/partials/templates/_funcs/get-page-images.html
blob: 268ceb4befec0ffbabe1a539ddf1b54bffba4acf (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
{{- $imgs := slice }}
{{- $imgParams := .Params.images }}
{{- $resources := .Resources.ByType "image" -}}
{{/* Find featured image resources if the images parameter is empty. */}}
{{- if not $imgParams }}
  {{- $featured := $resources.GetMatch "*feature*" -}}
  {{- if not $featured }}{{ $featured = $resources.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
  {{- with $featured }}
    {{- $imgs = $imgs | append (dict
      "Image" .
      "RelPermalink" .RelPermalink
      "Permalink" .Permalink) }}
  {{- end }}
{{- end }}
{{/* Use the first one of site images as the fallback. */}}
{{- if and (not $imgParams) (not $imgs) }}
  {{- with site.Params.images }}
    {{- $imgParams = first 1 . }}
  {{- end }}
{{- end }}
{{/* Parse page's images parameter. */}}
{{- range $imgParams }}
  {{- $img := . }}
  {{- $url := urls.Parse $img }}
  {{- if eq $url.Scheme "" }}
    {{/* Internal image. */}}
    {{- with $resources.GetMatch $img -}}
      {{/* Image resource. */}}
      {{- $imgs = $imgs | append (dict
        "Image" .
        "RelPermalink" .RelPermalink
        "Permalink" .Permalink) }}
    {{- else }}
      {{- $imgs = $imgs | append (dict
        "RelPermalink" (relURL $img)
        "Permalink" (absURL $img)
      ) }}
    {{- end }}
  {{- else }}
    {{/* External image */}}
    {{- $imgs = $imgs | append (dict
      "RelPermalink" $img
      "Permalink" $img
    ) }}
  {{- end }}
{{- end }}
{{- return $imgs }}