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

62 lines
1.8 KiB
HTML
Raw Normal View History

2024-01-30 12:34:00 +01:00
{{/* TODO: Ensure CSS/JS is only loaded once */}}
{{- with resources.Get "scss/snap-gallery.scss" | toCSS }}
<link rel="stylesheet" href="{{ .RelPermalink }}" crossorigin="anonymous">
2024-01-30 12:34:00 +01:00
{{- end }}
2024-01-30 12:18:28 +01:00
<script src="/js/snap-gallery.js"></script>
{{/* Initialise variables */}}
{{ $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">
2024-01-30 12:18:28 +01:00
{{ range $i, $img := $imgs }}
<div class="snap-image">
2024-01-30 12:18:28 +01:00
<img src="{{ $img }}" onclick="openModal();currentSlide({{ add $i 1 }});" class="hover-shadow">
</div>
{{ end }}
</div>
{{/* The Modal/Lightbox */}}
<div id="snap-modal" class="modal">
2024-01-30 12:18:28 +01:00
<span class="close cursor" onclick="closeModal()">&times;</span>
<div class="modal-content">
{{ range $i, $img := $imgs }}
<div class="snap-slide">
2024-01-30 12:18:28 +01:00
<div class="numbertext">{{ add $i 1 }} / {{ len $imgs }}</div>
<img src="{{ $img }}" style="width:100%">
</div>
{{ end }}
<!-- Next/previous controls -->
<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>
<!-- Thumbnail image controls -->
{{/* {{ range $i, $img := $imgs }}
<div class="snap-image">
<img class="img-thumb" src="{{ $img }}" onclick="currentSlide({{ add $i 1 }})" alt="Nature">
2024-01-30 12:18:28 +01:00
</div>
{{ end }} */}}
2024-01-30 12:18:28 +01:00
</div>
</div>