From f38f65d0115fe07bda6a6e4e60821789a511ee0b Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sat, 12 Aug 2023 17:33:39 +0100 Subject: [PATCH] fix: gallery lightbox doesn't always load Lightbox may not load in case of gallery shortcode contained within `text` field of a landing page block (v2 blocks). Fix #2972 --- .../layouts/partials/functions/parse_block_v2.html | 9 ++++++++- modules/wowchemy/layouts/partials/site_head.html | 1 - modules/wowchemy/layouts/partials/site_js.html | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/wowchemy/layouts/partials/functions/parse_block_v2.html b/modules/wowchemy/layouts/partials/functions/parse_block_v2.html index 040d8306..310f7dfc 100644 --- a/modules/wowchemy/layouts/partials/functions/parse_block_v2.html +++ b/modules/wowchemy/layouts/partials/functions/parse_block_v2.html @@ -11,11 +11,18 @@ {{ errorf "%s uses a `%s` block but the `%s` block was not found at `layouts/partials/%s`" $block.File.Path $block_type $block_type $block_path }} {{ end }} -{{/* Workaround to make Hugo's .Page.Store.Set cascade up to the parent of headless pages */}} +{{/* Mermaid block: Workaround to make Hugo's .Page.Store.Set cascade up to the parent of headless pages */}} {{ if $block.Page.Store.Get "has_mermaid" }} {{ $page.Page.Store.Set "has_mermaid" true }} {{ end }} +{{/* Gallery block: Workaround to make Hugo's .Page.Store.Set cascade up from page blocks to the page context */}} +{{/* Unfortunately, `.HasShortcode "gallery"` won't accept string input, only page context - so irrelevant here */}} +{{/* Therefore, must do our own search for shortcodes within the `text` string */}} +{{ if (gt (len (findRE `\{\{< gallery` $block.content.text 1)) 0) }} + {{ $page.Page.Store.Set "has_gallery" true }} +{{ end }} + {{/* Begin widget styling */}} {{ $bg := $block.design.background }} {{ $style := "" }} diff --git a/modules/wowchemy/layouts/partials/site_head.html b/modules/wowchemy/layouts/partials/site_head.html index 6ddeb2e7..0cefd15d 100644 --- a/modules/wowchemy/layouts/partials/site_head.html +++ b/modules/wowchemy/layouts/partials/site_head.html @@ -95,7 +95,6 @@ {{ $has_gallery = true }} {{ end }} {{ end }} - {{ $scr.Set "HasNestedGalleryShortcode" $has_gallery }} {{ if $has_gallery | or site.Params.require_fancybox }} {{ printf "" (printf $css.fancybox.url $css.fancybox.version) $css.fancybox.sri | safeHTML }} {{ end }} diff --git a/modules/wowchemy/layouts/partials/site_js.html b/modules/wowchemy/layouts/partials/site_js.html index 8d26f57f..3885f662 100644 --- a/modules/wowchemy/layouts/partials/site_js.html +++ b/modules/wowchemy/layouts/partials/site_js.html @@ -23,7 +23,7 @@ {{ end }} {{/* Workaround `.HasShortcode "gallery"` detection issue on `home/` WidgetPage v1 */}} - {{ if ($scr.Get "HasNestedGalleryShortcode") | or site.Params.require_fancybox }} + {{ if (.Page.Store.Get "has_gallery") | or site.Params.require_fancybox }} {{ printf "" (printf $js.fancybox.url $js.fancybox.version) $js.fancybox.sri | safeHTML }} {{ end }}