From 3deeaba3e4a5c0b1e67614d8ab6f5ba11badc5e3 Mon Sep 17 00:00:00 2001
From: Patrick Kollitsch <83281+davidsneighbour@users.noreply.github.com>
Date: Fri, 15 May 2026 01:53:35 +0000
Subject: [PATCH] fix: support images array for featured image
---
layouts/_partials/func/GetFeaturedImage.html | 28 ++++++++++++++++++++++++----
1 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/layouts/_partials/func/GetFeaturedImage.html b/layouts/_partials/func/GetFeaturedImage.html
index 9684d7f..a46ca4a 100644
--- a/layouts/_partials/func/GetFeaturedImage.html
+++ b/layouts/_partials/func/GetFeaturedImage.html
@@ -5,11 +5,14 @@
If a featured_image was set in the page's front matter, then that will be used.
- If not set, this will search page resources to find an image that contains the word
- "cover", and if found, returns the path to that resource.
+ If not set, this will use the first image from the page's images array.
- If no featured_image was set, and there's no "cover" image in page resources, then
- this partial returns an empty string (which evaluates to false).
+ If neither featured_image nor images was set, this will search page resources to
+ find an image that contains the word "cover", and if found, returns the path to
+ that resource.
+
+ If no featured image was set, and there's no "cover" image in page resources,
+ then this partial returns an empty string (which evaluates to false).
@return RelPermalink to featured image, or an empty string if not found.
@@ -18,8 +21,25 @@
{{/* Declare a new string variable, $linkToCover */}}
{{ $linkToCover := "" }}
{{ $matches := "feature,cover" }}
+{{ $featuredImage := "" }}
{{/* Use the value from front matter if present */}}
{{ with .Params.featured_image }}
+ {{ $featuredImage = . }}
+{{ else }}
+ {{ with .Params.images }}
+ {{ if reflect.IsSlice . }}
+ {{ if gt (len .) 0 }}
+ {{ with index . 0 }}
+ {{ $featuredImage = . }}
+ {{ end }}
+ {{ end }}
+ {{ else }}
+ {{ $featuredImage = . }}
+ {{ end }}
+ {{ end }}
+{{ end }}
+
+{{ with $featuredImage }}
{{/* This is the default case, the image lives in the static directory.
In which case we'll use the static dir */}}
{{ $linkToCover = strings.Trim . "/" | urls.AbsURL }}
--
Gitblit v1.10.0