Files
HugoBlox-kit/wowchemy/layouts/shortcodes/gallery.html
T
George Cushen bbca6dea78 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
2021-05-31 12:21:56 +01:00

33 lines
1.4 KiB
HTML

{{/* Gallery Shortcode for Wowchemy. */}}
{{/* Load gallery images from media library. */}}
{{/* Get album folder or default to `media/albums/gallery/`. */}}
{{ $album := (.Get "album") | default "gallery" }}
{{ $album_path := path.Join "media" "albums" $album "*" }}
{{/* Gallery options */}}
{{ $sort_order := .Get "order" | default "asc" }}
{{ $resize_options := .Get "resize_options" | default "x190" }}
<div class="gallery">
{{/* Attempt to automatically load gallery images from page bundle */}}
{{ $images := resources.Match $album_path }}
{{ range (sort $images "Name" $sort_order) }}
{{ $image := .Resize $resize_options }}
{{/* Check if the user set a caption for this image */}}
{{ $filename := path.Base .Name }}
{{ $caption := "" }}
{{ if $.Page.Params.gallery_item }}
{{ range (where (where $.Page.Params.gallery_item "album" $album) "image" $filename) }}
{{ $caption = .caption }}
{{ end }}
{{ end }}
<a data-fancybox="gallery-{{$album}}" href="{{ .RelPermalink }}" {{ with $caption }}data-caption="{{.|markdownify|emojify|safeHTMLAttr}}"{{ end }}>
<img src="{{ $image.RelPermalink }}" loading="lazy" alt="{{ plainify $caption | default $filename }}" width="{{ $image.Width }}" height="{{ $image.Height }}">{{/* Width & height (or low res src) required for lazy loading. */}}
</a>
{{else}}
{{ errorf "Unable to load gallery `%s` in `%s`." $album_path .Page.File.Filename }}
{{end}}
</div>