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

47 lines
1.6 KiB
HTML
Raw Normal View History

{{/* Count number of gallery on page */}}
{{- $.Page.Scratch.Add "gallerycount" 1 -}}
{{ $galno := $.Page.Scratch.Get "gallerycount" }}
2024-01-30 12:18:28 +01:00
{{/* 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 */}}
2024-01-30 12:18:28 +01:00
{{ $imgs := slice }}
2024-01-30 12:34:00 +01:00
{{/* Get/sanitise image paths */}}
2024-01-30 12:18:28 +01:00
{{ if .Params.isdir }}
2024-01-30 12:29:32 +01:00
{{/* Get images from folder, put into map */}}
{{ $imgdir := print "/static/" .Params.src }}
{{- range readDir $imgdir -}}
{{ $imgs = $imgs | append (print $.Params.src "/" .Name ) }}
{{ end }}
2024-01-30 12:18:28 +01:00
{{ else }}
2024-01-30 12:29:32 +01:00
{{/* Get images from src Param, separated by comma */}}
2024-01-30 12:18:28 +01:00
{{ range (split .Params.src ",") }}
{{ $imgs = $imgs | append (trim . " ") }}
{{ end }}
{{ 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) }}
{{/* Slideshow mode */}}
{{ else if eq $mode "slideshow" }}
{{ partial "slideshow" (dict "imgs" $imgs "galno" $galno) }}
{{/* Set autorotate timer for slideshow */}}
<script>const autoSlideshow = setInterval(moveSlideshowItem, 5000, {{ $galno }}, 1);</script>
{{ end }}
2024-01-30 12:18:28 +01:00
{{/* The Modal/Lightbox */}}
2024-02-01 15:10:31 +01:00
{{ partial "lightbox" (dict "galno" $galno "imgs" $imgs) }}