From bbca6dea786d3423b2a7ab2738bea4b5c7608660 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Mon, 31 May 2021 12:21:56 +0100 Subject: [PATCH] feat: load gallery from media dir & add gallery display options Add gallery `order` with options "asc" or "desc" Add gallery `resize_options` which supports Hugo image processing options. BREAKING CHANGE: Move gallery album folders to `assets/media/albums/`. Album name should be defined in shortcode as `album`. Fix #2245 --- wowchemy/layouts/partials/site_head.html | 22 ++++++++++++++++++-- wowchemy/layouts/partials/site_js.html | 2 +- wowchemy/layouts/shortcodes/gallery.html | 26 +++++++++--------------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/wowchemy/layouts/partials/site_head.html b/wowchemy/layouts/partials/site_head.html index 9c60a5ae..24428505 100644 --- a/wowchemy/layouts/partials/site_head.html +++ b/wowchemy/layouts/partials/site_head.html @@ -89,8 +89,26 @@ {{ end }} {{ printf "" (printf $css.fontAwesome.url $css.fontAwesome.version) $css.fontAwesome.sri | safeHTML }} - {{/* Workaround `.HasShortcode "gallery"` detection issue on `home/` WidgetPage v1 */}} - {{ if .HasShortcode "gallery" | or (and .IsHome (site.Params.require_fancybox | default true)) }} + {{/* Workaround `.HasShortcode "gallery"` not parsing page resources (widget page sections) */}} + {{ $has_gallery := false }} + {{/* Note: unless there is a root `/index.md` with `type: widget_page`, Hugo treats homepage as `page` type. */}} + {{ if (eq .Type "widget_page") | or (and .IsHome (eq .Type "page")) }} + {{/* Check if widget page sections use a gallery */}} + {{ $page := "/home/index.md" }} + {{ $context := cond .IsHome (site.GetPage $page) . }} + {{ range $context.Resources.ByType "page" }} + {{ if .HasShortcode "gallery" }} + {{ $has_gallery = true }} + {{ end }} + {{ end }} + {{ else }} + {{/* Single page */}} + {{ if .HasShortcode "gallery" }} + {{ $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/wowchemy/layouts/partials/site_js.html b/wowchemy/layouts/partials/site_js.html index 72e868ed..67d30a62 100644 --- a/wowchemy/layouts/partials/site_js.html +++ b/wowchemy/layouts/partials/site_js.html @@ -15,7 +15,7 @@ {{ end }} {{/* Workaround `.HasShortcode "gallery"` detection issue on `home/` WidgetPage v1 */}} - {{ if .HasShortcode "gallery" | or (and .IsHome (site.Params.require_fancybox | default true)) }} + {{ if ($scr.Get "HasNestedGalleryShortcode") | or site.Params.require_fancybox }} {{ printf "" (printf $js.fancybox.url $js.fancybox.version) $js.fancybox.sri | safeHTML }} {{ end }} diff --git a/wowchemy/layouts/shortcodes/gallery.html b/wowchemy/layouts/shortcodes/gallery.html index 847e8b77..6af6625f 100644 --- a/wowchemy/layouts/shortcodes/gallery.html +++ b/wowchemy/layouts/shortcodes/gallery.html @@ -1,26 +1,20 @@ {{/* Gallery Shortcode for Wowchemy. */}} -{{/* Load gallery images from page dir. */}} +{{/* Load gallery images from media library. */}} -{{/* Get album folder or default to `gallery/`. */}} +{{/* Get album folder or default to `media/albums/gallery/`. */}} {{ $album := (.Get "album") | default "gallery" }} +{{ $album_path := path.Join "media" "albums" $album "*" }} -{{/* Set image path and page bundle that images are associated with. */}} -{{ $album_path := "" }} -{{ $resource_page := "" }} -{{ if eq .Page.Parent.Type "widget_page" }} - {{ $album_path = printf "%s/%s/*" (path.Base (path.Split .Page.Path).Dir) $album }} - {{ $resource_page = $.Page.Parent }} -{{ else }} - {{ $album_path = printf "%s/*" $album }} - {{ $resource_page = $.Page }} -{{ end }} +{{/* Gallery options */}} +{{ $sort_order := .Get "order" | default "asc" }} +{{ $resize_options := .Get "resize_options" | default "x190" }} \ No newline at end of file