From ac88e8c0039017482348312bb641f0434e22f676 Mon Sep 17 00:00:00 2001 From: Mischa Date: Tue, 7 Jul 2026 08:35:32 +0200 Subject: [PATCH] fix(trip-cover): restrict cover picker to images + guard non-image selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The header.cover_image pagemediaselect field had no accept filter, so the Admin media picker listed every file in the trip page folder — including the GPX files placed there by the GPX manager. On a typical trip page (photos live on the journal entries, not the trip page) the picker offered *only* GPX, and selecting one routed a non-image Medium into cropResize, rendering a broken on both the trips list and the trip banner. - Blueprint: add `accept: ['.jpg','.jpeg','.png','.webp','.gif']` so the picker only offers images (prevention at source). - Macro: resolve cover_image against `media.images` instead of all media, so a non-image or unresolvable selection falls through to the entry-photo auto-pick (defence-in-depth; also hardens the R11 fallback). Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01RDS6t8wcpbwKvvrxykVQ5K --- themes/intotheeast/blueprints/trip.yaml | 1 + themes/intotheeast/templates/macros/cover.html.twig | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/themes/intotheeast/blueprints/trip.yaml b/themes/intotheeast/blueprints/trip.yaml index 6e22b60..f913581 100644 --- a/themes/intotheeast/blueprints/trip.yaml +++ b/themes/intotheeast/blueprints/trip.yaml @@ -39,6 +39,7 @@ form: header.cover_image: type: pagemediaselect + accept: ['.jpg', '.jpeg', '.png', '.webp', '.gif'] label: 'Cover Image' help: 'Pick from images uploaded to this trip page. Shown on the trips listing and the trip-page banner. Falls back to the first journal entry photo if left unset.' diff --git a/themes/intotheeast/templates/macros/cover.html.twig b/themes/intotheeast/templates/macros/cover.html.twig index bd0ed64..8b7b3e3 100644 --- a/themes/intotheeast/templates/macros/cover.html.twig +++ b/themes/intotheeast/templates/macros/cover.html.twig @@ -10,7 +10,10 @@ 3. else nothing. A set-but-missing cover_image (deleted/moved file) is `is not defined` in page media, so it falls through to the auto-pick rather than rendering a - broken image (R11). + broken image (R11). Resolution matches against `media.images` (not all + media), so a non-image selection — e.g. a `.gpx` from the trip page's own + media, which the picker used to offer — also falls through instead of + routing a non-image Medium into cropResize. Twig macros can only emit strings — they cannot return a Medium object — so resolution and rendering live together in one macro: it emits the @@ -22,8 +25,8 @@ #} {% macro render(trip_page, alt, w, h, wrapper_class, sizes) %} {%- set cover = null -%} -{%- if trip_page.header.cover_image and trip_page.media[trip_page.header.cover_image] is defined -%} - {%- set cover = trip_page.media[trip_page.header.cover_image] -%} +{%- if trip_page.header.cover_image and trip_page.media.images[trip_page.header.cover_image] is defined -%} + {%- set cover = trip_page.media.images[trip_page.header.cover_image] -%} {%- else -%} {%- set dailies_page = grav.pages.find(trip_page.route ~ '/dailies') -%} {%- if dailies_page -%}