I use Hugo to generate the static HTML pages for this website. One of the projects I’m working on involves a storyline which some of my friends do not want spoiled to them. So for this, I had to add a simple spoiler shortcode.
This spoiler shortcode works like this: . It can be used to individual phrases or whole blocks of text, as seen below.
Here is the source code to the spoiler tag functionality on my website:
// /theme/assets/css/spoiler.css
.spoiler_dummy {
display: none;
}
.spoiler_dummy:checked + label {
color: $color;
background: $background;
transition: color 0.3s ease, background 0.3s ease;
}
.spoiler {
position: relative;
display: inline-block;
cursor: help;
border-radius: 2px;
color: black;
background: black;
transition: color 0.3s ease, background 0.3s ease;
}
<!-- /theme/layouts/shortcodes/spoiler.html -->
<input class="spoiler_dummy" type="checkbox" id="spoilerTag{{ .Ordinal }}"/>
<label class="spoiler" for="spoilerTag{{ .Ordinal }}">
{{- .Inner | safeHTML -}}
</label>