Files
hugo-snap-gallery/layouts/shortcodes/snap-gallery.html

56 lines
2.1 KiB
HTML

{{/* Count number of gallery on page */}}
{{- $.Page.Scratch.Add "gallerycount" 1 -}}
{{ $galno := $.Page.Scratch.Get "gallerycount" }}
{{/* Load CSS/JS and make sure it is only loaded once */}}
{{- if eq ($.Page.Scratch.Get "gallerycount") 1 }}
{{- with resources.Get "scss/snap-gallery.scss" | toCSS }}
<link rel="stylesheet" href="{{ .RelPermalink }}" crossorigin="anonymous">
{{- end }}
<script src="/js/snap-gallery.js"></script>
{{ end }}
{{/* Initialise index of this gallery */}}
<script>imageIndex[{{ $galno }}] = 1;</script>
{{/* Initialise variables holding image paths */}}
{{ $imgs := slice }}
{{/* Get/sanitise image paths */}}
{{ if .Params.isdir }}
{{/* Get images from folder, put into map */}}
{{ $imgdir := print "/static/" .Params.src }}
{{- range readDir $imgdir -}}
{{ $imgs = $imgs | append (print $.Params.src "/" .Name ) }}
{{ end }}
{{ else }}
{{/* Get images from src Param, separated by comma */}}
{{ range (split .Params.src ",") }}
{{ $imgs = $imgs | append (trim . " ") }}
{{ end }}
{{ end }}
{{/* Define cursor when hovering over images, depending on lightbox status */}}
{{ $lightbox := (default true .Params.lightbox) }}
{{ $cursor := "auto" }}
{{ if $lightbox }}{{ $cursor = "zoom-in" }}{{ end }}
{{/* Visible images in separate modes */}}
{{ $mode := default "gallery" .Params.mode }}
{{/* Gallery mode */}}
{{ if eq $mode "gallery" }}
{{ partial "gallery" (dict "columns" .Params.columns "minwidth" .Params.minwidth "imgs" $imgs "galno" $galno "cursor" $cursor) }}
{{/* Slideshow mode */}}
{{ else if eq $mode "slideshow" }}
{{ partial "slideshow" (dict "imgs" $imgs "galno" $galno "width" .Params.slideshowwidth "cursor" $cursor) }}
{{/* Set autorotate timer for slideshow, if configured (default: yes) */}}
{{ if .Params.slideshowrotate }}
<script>const autoSlideshow = setInterval(moveSlideshowItem, {{ default 5000 .Params.slideshowrotate_timer }}, {{ $galno }}, 1, "auto");</script>
{{ end }}
{{ end }}
{{/* The Modal/Lightbox */}}
{{ if $lightbox }}
{{ partial "lightbox" (dict "galno" $galno "imgs" $imgs) }}
{{ end }}