index.html (921B)
1 {{ define "main" }} 2 3 {{ $imageDir := "static/images/rotating" }} 4 {{ $allowedExtensions := slice ".jpg" ".jpeg" ".png" ".webp" ".gif" }} 5 {{ $validImages := slice }} 6 7 {{/* Filter for valid image files only */}} 8 {{ range readDir $imageDir }} 9 {{ $ext := path.Ext .Name | lower }} 10 {{ if in $allowedExtensions $ext }} 11 {{ $validImages = $validImages | append .Name }} 12 {{ end }} 13 {{ end }} 14 15 <img id="rotating-image" src="" alt="Image" style="width: 100%; height: 100vh; object-fit: contain;"> 16 17 <script> 18 {{ if gt (len $validImages) 0 }} 19 const images = [ 20 {{ range $validImages }}"{{ . }}",{{ end }} 21 ]; 22 23 const randomImage = images[Math.floor(Math.random() * images.length)]; 24 document.getElementById('rotating-image').src = '/images/rotating/' + randomImage; 25 {{ else }} 26 document.getElementById('rotating-image').src = '/images/Avocado Mask,120x100cm,oil on canvas, 2020.jpg'; 27 {{ end }} 28 </script> 29 30 31 {{ end }}