24 lines
594 B
HTML
24 lines
594 B
HTML
<figure>
|
|
<img id="random-image" alt="Calvin&Hobbes random strip" />
|
|
<figcaption>copyright by Andrews McMeel Publishing</figcaption>
|
|
</figure>
|
|
|
|
<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>
|