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

40 lines
1.3 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
{{/* 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 */}}
<div class="snap-wrapper" style="--columns:{{ default 4 .Params.columns }};--min-width:{{ default 200 .Params.minwidth }};">
2024-01-30 12:18:28 +01:00
{{ range $i, $img := $imgs }}
<div class="snap-image">
2024-02-01 15:10:31 +01:00
<img src="{{ $img }}" onclick="openModal({{ $galno }});currentSlide({{ $galno }}, {{ add $i 1 }});">
2024-01-30 12:18:28 +01:00
</div>
{{ end }}
</div>
2024-02-01 15:10:31 +01:00
{{ partial "lightbox" (dict "galno" $galno "imgs" $imgs) }}
{{/* 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 }}
2024-01-30 22:47:35 +01:00
<script src="/js/snap-gallery.js"></script>
{{ end }}