gallery.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. {{ $album := "gallery" }}
  2. {{ with .Get "album" }}{{ $album = . }}{{ end }}
  3. {{ $album_path := printf "%s/*" $album }}
  4. {{/* if eq .Page.Type "home" */}}{{/* $album_path = "*" */}}{{/* end */}}
  5. <div class="gallery">
  6. {{/* Attempt to automatically load gallery images from page bundle */}}
  7. {{ $images := ($.Page.Resources.ByType "image").Match $album_path }}
  8. {{ with $images }}
  9. {{ range $images }}
  10. {{ $image := .Resize "x190" }}
  11. {{/* Check if the user set a caption for this image */}}
  12. {{ $filename := .Name }}
  13. {{ $caption := "" }}
  14. {{ if $.Page.Params.gallery_item }}
  15. {{ range (where $.Page.Params.gallery_item "album" $album) }}
  16. {{if eq (printf "%s/%s" $album .image) $filename}}{{ with .caption }}{{ $caption = . }}{{end}}{{end}}
  17. {{ end }}
  18. {{ end }}
  19. <a data-fancybox="gallery-{{$album}}" href="{{ .RelPermalink }}" {{ with $caption }}data-caption="{{.}}"{{ end }}>
  20. <img src="{{ $image.RelPermalink }}" alt="">
  21. </a>
  22. {{end}}
  23. {{else}}
  24. {{/* Load gallery images from the `static/img/` media library or internet */}}
  25. {{ if $.Page.Params.gallery_item }}
  26. {{ range (where $.Page.Params.gallery_item "album" $album) }}
  27. {{/* Set image path. */}}
  28. {{ $.Scratch.Set "src" .image }}
  29. {{ if gt (len .image) 4 }}
  30. {{ if ne "http" (slicestr .image 0 4) }}
  31. {{ $.Scratch.Set "src" (printf "img/%s" .image | relURL) }}
  32. {{ end }}
  33. {{ end }}
  34. <a data-fancybox="gallery{{ with .album }}-{{.}}{{ end }}" {{ with .caption }}data-caption="{{.}}"{{ end }} href="{{$.Scratch.Get "src"}}">
  35. <img src="{{$.Scratch.Get "src"}}" alt="">
  36. </a>
  37. {{end}}
  38. {{else}}
  39. {{ errorf "Unable to load gallery in %s." .Page.Filename }}
  40. {{end}}
  41. {{end}}
  42. </div>