From b1e399fa005bcf62d2a10d4fd826d9da35ccba92 Mon Sep 17 00:00:00 2001 From: Mark Dumay <61946753+markdumay@users.noreply.github.com> Date: Sun, 5 Jul 2026 06:36:29 +0200 Subject: [PATCH] fix(lightbox): load shell and JS as core so fullscreen is reliable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lightbox shell and its JS were gated on a `lightbox` module dependency that shortcodes register via AddModule during content rendering. Per Hugo's docs a value set that way is "indeterminate until Hugo renders the page content", so the head/footer templates that read it — the shell include and the optional-scripts pass — saw it only intermittently. Pages using a fullscreen/lightbox shortcode rendered the trigger button but often not the dialog or its JS. Make the lightbox core theme furniture: render the shell on every page and bundle its JS into the core set. Any [data-lightbox-trigger] now works without per-page module registration. Drop the now-vestigial AddModule call from the trigger partial. --- config/_default/params.toml | 7 +++- .../_partials/assets/lightbox-trigger.html | 7 ++-- layouts/_partials/assets/lightbox.html | 36 ++++++++++--------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/config/_default/params.toml b/config/_default/params.toml index 156fc51a..d3f5caf0 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -309,6 +309,11 @@ img-src = ["i.vimeocdn.com"] script-src = ["player.vimeo.com"] +# Core furniture: the lightbox shell (assets/lightbox.html) and its JS +# both load on every page so any [data-lightbox-trigger] works without per-page +# module registration. Kept out of the optional set on purpose — a shortcode +# registering it via AddModule is a render-order-dependent side effect that a +# head/footer consumer cannot rely on (see assets/lightbox.html). [modules.lightbox] - integration = "optional" + integration = "core" state = "defer" diff --git a/layouts/_partials/assets/lightbox-trigger.html b/layouts/_partials/assets/lightbox-trigger.html index 49cddb32..2a8b9888 100644 --- a/layouts/_partials/assets/lightbox-trigger.html +++ b/layouts/_partials/assets/lightbox-trigger.html @@ -1,15 +1,14 @@ {{/* - Convenience: render a lightbox trigger button for arbitrary content and - register the `lightbox` module dependency. Call with: + Convenience: render a lightbox trigger button for arbitrary content. The + lightbox shell and JS are core theme furniture (always present), so no + module registration is needed. Call with: {{ partial "assets/lightbox-trigger.html" (dict "page" . "source" "#my-figure") }} `source` is a CSS selector for the node to clone into the lightbox. Keep it unique: an id selector must not collide with a Hugo heading anchor (heading/page slug), or querySelector may match the wrong element. */}} -{{- $page := .page | default page -}} {{- $source := .source -}} {{- $icon := partial "utilities/GetThemeIcon.html" (dict "id" "lightboxExpand" "default" "fas expand") -}} -{{- partial "utilities/AddModule.html" (dict "page" $page "module" "lightbox") -}} - - -{{- end -}} +{{- $close := partial "utilities/GetThemeIcon.html" (dict "id" "lightboxClose" "default" "fas xmark") -}} + + + +