123456789101112131415161718192021222324252627282930313233343536373839 |
- {{/* Gallery Shortcode for Wowchemy. */}}
- {{/* Load gallery images from page dir. */}}
- {{/* Get album folder or default to `gallery/`. */}}
- {{ $album := (.Get "album") | default "gallery" }}
- {{/* 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 }}
- <div class="gallery">
- {{/* Attempt to automatically load gallery images from page bundle */}}
- {{ $images := ($resource_page.Resources.ByType "image").Match $album_path }}
- {{ range $images }}
- {{ $image := .Resize "x190" }}
- {{/* 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 in %s." .Page.File.Filename }}
- {{end}}
- </div>
|