gallery.html 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. {{/* Gallery Shortcode for Wowchemy. */}}
  2. {{/* Load gallery images from media library. */}}
  3. {{/* Get album folder or default to `media/albums/gallery/`. */}}
  4. {{ $album := (.Get "album") | default "gallery" }}
  5. {{ $album_path := path.Join "media" "albums" $album "*" }}
  6. {{/* Gallery options */}}
  7. {{ $sort_order := .Get "order" | default "asc" }}
  8. {{ $resize_options := printf "%s webp" (.Get "resize_options" | default "x190") }}
  9. <div class="gallery">
  10. {{/* Attempt to automatically load gallery images from page bundle */}}
  11. {{ $images := resources.Match $album_path }}
  12. {{ range (sort $images "Name" $sort_order) }}
  13. {{ $image := .Resize $resize_options }}
  14. {{/* Check if the user set a caption for this image */}}
  15. {{ $filename := path.Base .Name }}
  16. {{ $caption := "" }}
  17. {{ if $.Page.Params.gallery_item }}
  18. {{ range (where (where $.Page.Params.gallery_item "album" $album) "image" $filename) }}
  19. {{ $caption = .caption }}
  20. {{ end }}
  21. {{ end }}
  22. <a data-fancybox="gallery-{{$album}}" href="{{ .RelPermalink }}" {{ with $caption }}data-caption="{{.|markdownify|emojify|safeHTMLAttr}}"{{ end }}>
  23. <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. */}}
  24. </a>
  25. {{else}}
  26. {{ errorf "Unable to load gallery `%s` in `%s`." $album_path .Page.File.Filename }}
  27. {{end}}
  28. </div>