Files
HugoBlox-kit/layouts/shortcodes/gallery.html
T
George Cushen 0ff174bbf4 feat(shortcodes): add support for image gallery in page bundle
To use:

1. Create a gallery album folder in page bundle
2. Add images to album folder
3. Paste `{{< gallery album="<ALBUM FOLDER>" >}}` in your page content

Close #786
2018-11-03 23:27:03 +00:00

38 lines
1.4 KiB
HTML

{{ $album := "gallery" }}
{{ with .Get "album" }}{{ $album = . }}{{ end }}
<div class="gallery">
{{/* Attempt to automatically load gallery images from page bundle */}}
{{ $images := ($.Page.Resources.ByType "image").Match (printf "%s/*" $album) }}
{{ with $images }}
{{ range $images }}
{{/* Check if the user set a caption for this image */}}
{{ $filename := .Name }}
{{ $caption := "" }}
{{ if $.Page.Params.gallery_item }}
{{ range (where $.Page.Params.gallery_item "album" $album) }}
{{if eq (printf "%s/%s" $album .image) $filename}}{{ with .caption }}{{ $caption = . }}{{end}}{{end}}
{{ end }}
{{ end }}
<a data-fancybox="gallery-{{$album}}" href="{{ .RelPermalink }}" {{ with $caption }}data-caption="{{.}}"{{ end }}>
<img src="{{ .RelPermalink }}" alt="">
</a>
{{end}}
{{else}}
{{/* Load gallery images from the `static/img/` media library or internet */}}
{{ range (where $.Page.Params.gallery_item "album" $album) }}
{{/* Set image path. */}}
{{ $.Scratch.Set "src" .image }}
{{ if gt (len .image) 4 }}
{{ if ne "http" (slicestr .image 0 4) }}
{{ $.Scratch.Set "src" (printf "img/%s" .image | relURL) }}
{{ end }}
{{ end }}
<a data-fancybox="gallery{{ with .album }}-{{.}}{{ end }}" {{ with .caption }}data-caption="{{.}}"{{ end }} href="{{$.Scratch.Get "src"}}">
<img src="{{$.Scratch.Get "src"}}" alt="">
</a>
{{ end }}
{{end}}
</div>