21 lines
507 B
HTML
21 lines
507 B
HTML
<img id="random-image" alt="Calvin&Hobbes random strip" />
|
|
|
|
<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>
|