New theme blowfish
This commit is contained in:
20
layouts/shortcodes/random-image.html
Normal file
20
layouts/shortcodes/random-image.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<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>
|
Reference in New Issue
Block a user