summaryrefslogtreecommitdiff
path: root/layouts/partials/templates/_funcs
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2025-09-01 11:27:12 -0700
committerrtk0c <[email protected]>2025-09-01 11:27:12 -0700
commit86b0d0c422e34c38837b5b5495ad6d295d0e73d2 (patch)
tree039e513e5cebe1ba60b747372b50d8049edf29ae /layouts/partials/templates/_funcs
Squashed 'themes/PaperMod/' content from commit 5a46517
git-subtree-dir: themes/PaperMod git-subtree-split: 5a4651783fa9159123d947bd3511b355146d4797
Diffstat (limited to 'layouts/partials/templates/_funcs')
-rw-r--r--layouts/partials/templates/_funcs/get-page-images.html47
1 files changed, 47 insertions, 0 deletions
diff --git a/layouts/partials/templates/_funcs/get-page-images.html b/layouts/partials/templates/_funcs/get-page-images.html
new file mode 100644
index 0000000..268ceb4
--- /dev/null
+++ b/layouts/partials/templates/_funcs/get-page-images.html
@@ -0,0 +1,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 }}