gallery.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. {{/* Gallery Shortcode for Wowchemy. */}}
  2. {{/* Load gallery images from page dir. */}}
  3. {{/* Get album folder or default to `gallery/`. */}}
  4. {{ $album := (.Get "album") | default "gallery" }}
  5. {{/* Set image path and page bundle that images are associated with. */}}
  6. {{ $album_path := "" }}
  7. {{ $resource_page := "" }}
  8. {{ if eq .Page.Parent.Type "widget_page" }}
  9. {{ $album_path = printf "%s/%s/*" (path.Base (path.Split .Page.Path).Dir) $album }}
  10. {{ $resource_page = $.Page.Parent }}
  11. {{ else }}
  12. {{ $album_path = printf "%s/*" $album }}
  13. {{ $resource_page = $.Page }}
  14. {{ end }}
  15. <div class="gallery">
  16. {{/* Attempt to automatically load gallery images from page bundle */}}
  17. {{ $images := ($resource_page.Resources.ByType "image").Match $album_path }}
  18. {{ range $images }}
  19. {{ $image := .Resize "x190" }}
  20. {{/* Check if the user set a caption for this image */}}
  21. {{ $filename := path.Base .Name }}
  22. {{ $caption := "" }}
  23. {{ if $.Page.Params.gallery_item }}
  24. {{ range (where (where $.Page.Params.gallery_item "album" $album) "image" $filename) }}
  25. {{ $caption = .caption }}
  26. {{ end }}
  27. {{ end }}
  28. <a data-fancybox="gallery-{{$album}}" href="{{ .RelPermalink }}" {{ with $caption }}data-caption="{{.|markdownify|emojify|safeHTMLAttr}}"{{ end }}>
  29. <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. */}}
  30. </a>
  31. {{else}}
  32. {{ errorf "Unable to load gallery in %s." .Page.File.Filename }}
  33. {{end}}
  34. </div>