website_lea/layouts/partials/scratch.html

34 lines
1.2 KiB
HTML

{{ $folder := (print "/content/cinema/gallery/") }}
{{ if .File }}
{{ $folder = (print "/content/" .File.Dir "gallery/") }}
{{ end }}
{{ $img := newScratch }}
{{ $files := readDir $folder }}
{{ $img.Set "max" 0 }}
{{ range sort $files "Name" "asc" }}
{{ if not .IsDir }}
{{ if not (in .Name "thumb") }}
{{ $img.Add "list" (slice .Name) }}
{{ $img.Set "max" (add ($img.Get "max") 1) }}
{{ end }}
{{ end }}
{{ end }}
{{ range $index, $val := $img.Get "list" }}
{{ $curr := index (split $val ".") 0 }}
{{ $prec := mod (add (sub $index 1) ($img.Get "max")) ($img.Get "max") }}
{{ $next := mod (add $index 1) ($img.Get "max") }}
<a id="img{{ $index }}_h" class="thumb hidden_link" href="#img{{ $index }}">
<picture>
<source srcset="gallery/{{ $curr }}.thumb.avif" type="image/avif"/>
<source srcset="gallery/{{ $curr }}.thumb.webp" type="image/webp"/>
<img src="gallery/{{ $curr }}.thumb.jpg"/>
</picture>
</a>
<!-- lightbox container hidden with CSS -->
<div class="lightbox" id="img{{ $index }}">
<a href="#img{{ $prec }}" class="light-btn hidden_link btn-prev"><<</a>
<a href="#_" class="btn-close hidden_link">X</a>
<img src="gallery/{{ $val }}">
<a href="#img{{ $next }}" class="light-btn hidden_link btn-next">>></a>
</div>
{{ end }}