From c48b65edb2ae88809f44413320cd77681227e868 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Mon, 29 Dec 2025 00:02:24 +0000 Subject: [PATCH] feat: safely parse `image` front matter structure --- .../_partials/functions/get_featured_image.html | 5 ++++- .../layouts/_partials/views/card.html | 5 ++++- modules/blox-tailwind/layouts/events/page.html | 17 +++++++++++------ modules/blox-tailwind/layouts/single.html | 17 +++++++++++------ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/modules/blox-tailwind/layouts/_partials/functions/get_featured_image.html b/modules/blox-tailwind/layouts/_partials/functions/get_featured_image.html index f20d0c4b..2eb3fbb0 100644 --- a/modules/blox-tailwind/layouts/_partials/functions/get_featured_image.html +++ b/modules/blox-tailwind/layouts/_partials/functions/get_featured_image.html @@ -13,7 +13,10 @@ {{ $resource := (.Resources.ByType "image").GetMatch "*featured*" }} {{ if eq $resource nil }} {{/* Otherwise fall back the image file specified in front matter */}} - {{ $filename := .Params.image.filename }} + {{ $filename := "" }} + {{ if and .Params.image (reflect.IsMap .Params.image) }} + {{ $filename = .Params.image.filename }} + {{ end }} {{/* Search in page folder */}} {{ $resource = (.Resources.ByType "image").GetMatch $filename }} {{/* Otherwise in `assets/media/` folder */}} diff --git a/modules/blox-tailwind/layouts/_partials/views/card.html b/modules/blox-tailwind/layouts/_partials/views/card.html index c38c8347..339f1070 100644 --- a/modules/blox-tailwind/layouts/_partials/views/card.html +++ b/modules/blox-tailwind/layouts/_partials/views/card.html @@ -8,7 +8,10 @@ {{ end }} {{ $resource := partial "functions/get_featured_image.html" $item }} -{{ $anchor := $item.Params.image.focal_point | default "Center" }} +{{ $anchor := "Center" }} +{{ if and $item.Params.image (reflect.IsMap $item.Params.image) }} + {{ $anchor = $item.Params.image.focal_point | default "Center" }} +{{ end }} {{ $fill_image := .config.fill_image | default true }} {{ $showDate := .config.show_date | default true }} {{ $showReadTime := .config.show_read_time | default true }} diff --git a/modules/blox-tailwind/layouts/events/page.html b/modules/blox-tailwind/layouts/events/page.html index 1f4fed74..0db59cde 100644 --- a/modules/blox-tailwind/layouts/events/page.html +++ b/modules/blox-tailwind/layouts/events/page.html @@ -251,12 +251,17 @@ {{ else }} {{/* Fallback to featured image if no slides */}} {{ $featured := partial "functions/get_featured_image.html" . }} - {{ if and $featured (not .Params.image.preview_only) }} + {{/* Safely extract image parameters - handle case where image is not a map */}} + {{ $image_params := dict }} + {{ if and .Params.image (reflect.IsMap .Params.image) }} + {{ $image_params = .Params.image }} + {{ end }} + {{ if and $featured (not $image_params.preview_only) }} {{/* Fit image within max size. */}} {{ $image := $featured }} {{/* Determine image placement. */}} - {{ $placement := .Params.image.placement | default 1 }}{{/* Default to full column width. */}} + {{ $placement := $image_params.placement | default 1 }}{{/* Default to full column width. */}} {{/* Configure responsive processing based on placement */}} {{ $image_container := "" }} {{ $responsive_sizes := slice }} @@ -301,10 +306,10 @@ src="{{ $responsive.fallback.RelPermalink }}" width="{{ $fitted_image.Width }}" height="{{ $fitted_image.Height }}" - alt="{{ with $.Params.image.alt_text }}{{.}}{{ end }}" + alt="{{ with $image_params.alt_text }}{{.}}{{ end }}" class="featured-image" fetchpriority="high"> - {{ with $.Params.image.caption }}{{ . | markdownify | emojify }}{{ end }} + {{ with $image_params.caption }}{{ . | markdownify | emojify }}{{ end }} {{ else }} @@ -322,10 +327,10 @@ {{ with $.Params.image.alt_text }}{{.}}{{ end }} - {{ with $.Params.image.caption }}{{ . | markdownify | emojify }}{{ end }} + {{ with $image_params.caption }}{{ . | markdownify | emojify }}{{ end }} {{ end }} diff --git a/modules/blox-tailwind/layouts/single.html b/modules/blox-tailwind/layouts/single.html index af6ff9d0..5bf4cf9c 100644 --- a/modules/blox-tailwind/layouts/single.html +++ b/modules/blox-tailwind/layouts/single.html @@ -147,13 +147,18 @@ {{ $featured := partial "functions/get_featured_image.html" . }} + {{/* Safely extract image parameters - handle case where image is not a map */}} + {{ $image_params := dict }} + {{ if and .Params.image (reflect.IsMap .Params.image) }} + {{ $image_params = .Params.image }} + {{ end }} {{/* Featured image layout */}} - {{ if and $featured (not .Params.image.preview_only) }} + {{ if and $featured (not $image_params.preview_only) }} {{/* Fit image within max size. */}} {{ $image := $featured }} {{/* Determine image placement. */}} - {{ $placement := .Params.image.placement | default 1 }}{{/* Default to full column width. */}} + {{ $placement := $image_params.placement | default 1 }}{{/* Default to full column width. */}} {{/* Configure responsive processing based on placement */}} {{ $image_container := "" }} {{ $responsive_sizes := slice }} @@ -198,10 +203,10 @@ src="{{ $responsive.fallback.RelPermalink }}" width="{{ $fitted_image.Width }}" height="{{ $fitted_image.Height }}" - alt="{{ with $.Params.image.alt_text }}{{.}}{{ end }}" + alt="{{ with $image_params.alt_text }}{{.}}{{ end }}" class="featured-image" fetchpriority="high"> - {{ with $.Params.image.caption }}{{ . | markdownify | emojify }}{{ end }} + {{ with $image_params.caption }}{{ . | markdownify | emojify }}{{ end }} {{ else }} @@ -219,10 +224,10 @@ {{ with $.Params.image.alt_text }}{{.}}{{ end }} - {{ with $.Params.image.caption }}{{ . | markdownify | emojify }}{{ end }} + {{ with $image_params.caption }}{{ . | markdownify | emojify }}{{ end }} {{ end }}