Files
hugo-snap-gallery/layouts/shortcodes/snap-gallery.html
2024-01-30 22:47:35 +01:00

56 lines
1.7 KiB
HTML

{{/* TODO: Ensure CSS/JS is only loaded once */}}
{{- with resources.Get "scss/snap-gallery.scss" | toCSS }}
<link rel="stylesheet" href="{{ .RelPermalink }}" crossorigin="anonymous">
{{- end }}
{{/* Initialise variables */}}
{{ $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 }}
{{/* Visible images */}}
<div class="snap-wrapper">
{{ range $i, $img := $imgs }}
<div class="snap-image">
<img src="{{ $img }}" onclick="openModal();currentSlide({{ add $i 1 }});" class="hover-shadow">
</div>
{{ end }}
</div>
{{/* The Modal/Lightbox */}}
<div class="snap-lightbox">
{{ range $i, $img := $imgs }}
<div class="snap-lightbox-inner">
<div class="numbertext">{{ add $i 1 }} / {{ len $imgs }}</div>
<img src="{{ $img }}" style="width:100%">
</div>
{{ end }}
<!-- Close and Next/previous controls -->
<span class="snap-close" onclick="closeModal()">&times;</span>
<a class="snap-lightbox-prev" onclick="plusSlides(-1)"><i class="snap-lightbox-arrow"></i></a>
<a class="snap-lightbox-next" onclick="plusSlides(1)"><i class="snap-lightbox-arrow"></i></a>
{{/* <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a> */}}
{{/* <!-- Caption text -->
<div class="caption-container">
<p id="caption"></p>
</div> */}}
</div>
<script src="/js/snap-gallery.js"></script>