Created
April 18, 2023 22:42
-
-
Save TheCoreMan/9fff946f3cda9b98e5b8118d34318c47 to your computer and use it in GitHub Desktop.
Hugo flashcard HTML Shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Made by Shay Nehmad, feel free to use. For details see | |
https://mrnice.dev/posts/hugo-flashcard-shortcode-for-study/ | |
--> | |
<!-- This "with" is for error handling, see | |
https://gohugo.io/templates/shortcode-templates/#error-handling-in-shortcodes | |
--> | |
{{ with .Get "question" }} | |
<!-- get a random string to add to each ID --> | |
{{ $seed := now.Format ":time_full" }} {{ $random := delimit (shuffle (split | |
(md5 $seed) "" )) "" }} | |
<!-- create a unique ID for the answer, based on the question's SHA and the | |
random string. --> | |
{{ $questionSHA := . | sha1 }} {{ $answerID := printf "answer-id-%s-%s" | |
$questionSHA $random }} | |
<!-- The CSS and JS for the flashcard --> | |
<link rel="stylesheet" href="/css/flashcard.css" /> | |
<script src="/js/flashcard.js"></script> | |
<!-- The flashcard itself --> | |
<div class="flashcard"> | |
<div class="notepad-line"></div> | |
<button | |
class="flashcard__front" | |
onclick="toggleAnswer({{ $answerID }})" | |
role="button" | |
> | |
{{ . | markdownify }} | |
</button> | |
<div id="{{ $answerID }}" class="flashcard__back"> | |
{{ $.Inner | markdownify }} | |
</div> | |
</div> | |
<!-- Error handling stuff --> | |
{{ else }} {{ errorf "missing value for param 'question': %s" .Position }} {{ | |
end }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment