Merge pull request 'Add missing JSON.parse, proper random id generation and more images' (#34) from improve_thanks into main

Reviewed-on: #34
pull/37/head
sixtus 2022-02-27 12:12:03 +01:00
commit fc6b784a15
4 changed files with 4 additions and 2 deletions

View File

@ -13,6 +13,8 @@ image:
- /intern/thanks/awesome-dog.jpg
- /intern/thanks/could-you-get-any-cooler.jpg
- /intern/thanks/t_hanks.jpg
- /intern/thanks/thank-you.jpg
- /intern/thanks/thanks-for-your-help.jpg
---
{{< random_image >}}

View File

@ -3,14 +3,14 @@
{{- errorf "missing value for 'image.choices': %s" .Position }}
{{- end }}
{{- $alt := default "random image" ($.Page.Param "image.alt") }}
{{- $id := sha256 now.UnixNano }}
{{- $id := sha256 (index (seq 999 | shuffle) 0) }}
<p id="{{ $id }}">
<img class="centered pad-vertical" >
</p>
<script>
document.addEventListener("DOMContentLoaded", function() {
const container = document.getElementById("{{ $id }}");
const choices = {{ $choices }};
const choices = JSON.parse(`{{ $choices }}`);
if (!container || !choices) { return; }
const img = document.createElement("img");
img.alt = "{{ $alt }}";

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB