This repository has been archived on 2024-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
2022-02-20 20:48:24 +00:00
|
|
|
{{- $choices := $.Page.Param "image.choices" }}
|
|
|
|
{{- if not $choices }}
|
|
|
|
{{- errorf "missing value for 'image.choices': %s" .Position }}
|
|
|
|
{{- end }}
|
|
|
|
{{- $alt := default "random image" ($.Page.Param "image.alt") }}
|
2022-02-27 11:10:14 +00:00
|
|
|
{{- $id := sha256 (index (seq 999 | shuffle) 0) }}
|
2023-01-01 16:52:19 +00:00
|
|
|
<p id="{{ $id }}"></p>
|
2022-02-20 20:48:24 +00:00
|
|
|
<script>
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
|
const container = document.getElementById("{{ $id }}");
|
2022-02-26 21:13:33 +00:00
|
|
|
const choices = JSON.parse(`{{ $choices }}`);
|
2022-02-20 20:48:24 +00:00
|
|
|
if (!container || !choices) { return; }
|
|
|
|
const img = document.createElement("img");
|
|
|
|
img.alt = "{{ $alt }}";
|
2023-01-01 16:41:38 +00:00
|
|
|
img.classList.add("centered");
|
2022-02-20 20:48:24 +00:00
|
|
|
img.src = choices[Math.floor(Math.random() * choices.length)];
|
|
|
|
container.appendChild(img);
|
|
|
|
})
|
|
|
|
</script>
|