Files
ettore.dreucci.it/layouts/shortcodes/random-image.html
2025-10-10 00:33:18 +02:00

21 lines
493 B
HTML

<img id="random-image" alt="Random image" />
<script>
const images = [
{{- $files := readDir "static/img/calvin_hobbes" -}}
{{- range $i, $f := $files -}}
{{- if not $f.IsDir -}}
"{{ printf "/img/calvin_hobbes/%s" $f.Name }}",
{{- end -}}
{{- end -}}
];
(function(){
if(images.length === 0) return;
var img = document.getElementById("random-image");
if(!img) return;
var rand = images[Math.floor(Math.random() * images.length)];
img.src = rand;
})();
</script>