Hack together some random image display and create some "thank you" page with it

This commit is contained in:
sixtus 2022-02-20 21:48:24 +01:00
parent b44da3985a
commit 0591754542
5 changed files with 41 additions and 0 deletions

20
content/intern/thanks.md Normal file
View File

@ -0,0 +1,20 @@
---
title: Danke!
slug: thanks
description: Vielen Dank!
draft: false
showmetadates: false
showmetalinks: false
aliases:
- /danke
image:
alt: Thank you!
choices:
- /intern/thanks/awesome-dog.jpg
- /intern/thanks/could-you-get-any-cooler.jpg
- /intern/thanks/t_hanks.jpg
---
{{< random_image >}}
Super gut!

View File

@ -0,0 +1,21 @@
{{- $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") }}
{{- $id := sha256 now.UnixNano }}
<p id="{{ $id }}">
<img class="centered pad-vertical" >
</p>
<script>
document.addEventListener("DOMContentLoaded", function() {
const container = document.getElementById("{{ $id }}");
const choices = {{ $choices }};
if (!container || !choices) { return; }
const img = document.createElement("img");
img.alt = "{{ $alt }}";
img.classList.add("centered", "pad-vertical");
img.src = choices[Math.floor(Math.random() * choices.length)];
container.appendChild(img);
})
</script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB