Files
static-site-pipeline/hugo/layouts/shortcodes/foldergallery.html
2024-03-14 20:50:23 +00:00

26 lines
1.2 KiB
HTML

<details>
{{ $summary := default "Click to view gallery" (.Get "summary") }}
<summary>{{ $summary }}</summary>
<div class="gallery">
{{ $base := .Get "src" }}
{{ $path := print "static/" (.Get "src") }}
{{ $galleryName := default "gallery" (.Get "galleryName") }}
{{ range (readDir $path) }}
{{- $thumbext := "-thumb" }}
{{- $isthumb := .Name | findRE ($thumbext | printf "%s\\.") }}<!-- is the current file a thumbnail image? -->
{{- $isimg := lower .Name | findRE "\\.(gif|jpg|jpeg|tiff|png|bmp)" }}<!-- is the current file an image? -->
{{- if and $isimg (not $isthumb) }}
{{- $thumb := .Name | replaceRE "(\\.[^.]+)" ($thumbext | printf "%s.jpg") }}
{{- $alttextfile := .Name | replaceRE "(\\..+)" ".md" }}
{{- $alttext := printf "%s/%s" $path $alttextfile | os.ReadFile }}
<a data-fancybox="{{ $galleryName }}" data-caption="{{ $alttext }}" href="/{{ $base }}/{{ .Name }}">
<img src="/{{ $base }}/{{ $thumb }}" width=100 height=100 alt={{ $.Page.RenderString $alttext }}> <br/>
</a>
{{- end }}
{{ end }}
<script>document.addEventListener('DOMContentLoaded', function() {
Fancybox.bind('[data-fancybox="{{ $galleryName }}"]', {});
});</script>
</div>
</details>