diff options
author | tdro <tdro@noreply.example.com> | 2022-11-21 11:23:56 -0500 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-11-21 11:23:56 -0500 |
commit | 8113e9c39376d1e9fb1c239a678a7502272e8fda (patch) | |
tree | fc1e9263021d886db60a1b22d3cfee3b7bfa410d /themes/default/layouts/shortcodes | |
parent | 4a82e6046ab0e8cf65a089a7b1e85c6ef918666c (diff) | |
download | canory-8113e9c39376d1e9fb1c239a678a7502272e8fda.tar.gz canory-8113e9c39376d1e9fb1c239a678a7502272e8fda.tar.bz2 canory-8113e9c39376d1e9fb1c239a678a7502272e8fda.zip |
themes/default/layouts: Use hashing algorithm consistently
Avoid using shuffle in short codes by appending .Ordinal value
Diffstat (limited to 'themes/default/layouts/shortcodes')
-rw-r--r-- | themes/default/layouts/shortcodes/abbr.html | 6 | ||||
-rw-r--r-- | themes/default/layouts/shortcodes/spoiler.html | 8 | ||||
-rw-r--r-- | themes/default/layouts/shortcodes/spoiler.rss.xml | 4 |
3 files changed, 12 insertions, 6 deletions
diff --git a/themes/default/layouts/shortcodes/abbr.html b/themes/default/layouts/shortcodes/abbr.html index 52e3ff9..bad8895 100644 --- a/themes/default/layouts/shortcodes/abbr.html +++ b/themes/default/layouts/shortcodes/abbr.html @@ -1,8 +1,8 @@ {{- $abbr := default "TL;DR:" (.Get "abbr" | default (.Get 0)) -}} {{- $title := default "Too long, didn't read" (.Get "title" | default (.Get 1)) -}} +{{- $hash := print (truncate 8 "" (sha256 $abbr)) .Ordinal -}} -{{- $id := delimit (shuffle (seq 0 20)) "" -}} -<input hidden type="checkbox" id="abbr-{{ $id }}" /> +<input hidden type="checkbox" id="abbr-{{ $hash }}" /> {{- /* This comment removes trailing newlines and white spaces. */ -}} -<abbr title="{{ $title }}"><label for="abbr-{{ $id }}">{{ $abbr | markdownify }}</label></abbr> +<abbr title="{{ $title }}"><label for="abbr-{{ $hash }}">{{ $abbr | markdownify }}</label></abbr> {{- /* This comment removes trailing newlines and white spaces. */ -}} diff --git a/themes/default/layouts/shortcodes/spoiler.html b/themes/default/layouts/shortcodes/spoiler.html index fd3c9d3..ebc3643 100644 --- a/themes/default/layouts/shortcodes/spoiler.html +++ b/themes/default/layouts/shortcodes/spoiler.html @@ -1,9 +1,13 @@ {{- $text := default "This is a spoiler." (.Get "text" | default (.Get 0)) -}} {{- $title := default "Click to show/hide text." (.Get "title" | default (.Get 1)) -}} +{{- $hash := print (truncate 8 "" (sha256 $text)) .Ordinal -}} {{- if gt (len .Inner) 1 -}} {{- $text = .Inner -}} {{- end -}} -<input hidden type="checkbox" id="spoiler-text-{{ md5 $text }}" /> -<s title="{{ $title }}"><label for="spoiler-text-{{ md5 $text }}">{{ $text | markdownify }}</label></s> +<input hidden type="checkbox" id="spoiler-text-{{ $hash }}" /> + +<s title="{{ $title }}"> + <label for="spoiler-text-{{ $hash }}">{{ $text | markdownify }}</label> +</s> diff --git a/themes/default/layouts/shortcodes/spoiler.rss.xml b/themes/default/layouts/shortcodes/spoiler.rss.xml index 73dde8a..adbce7b 100644 --- a/themes/default/layouts/shortcodes/spoiler.rss.xml +++ b/themes/default/layouts/shortcodes/spoiler.rss.xml @@ -5,4 +5,6 @@ {{ $text = .Inner }} {{ end }} -<s title="{{ $title }}"><label for="spoiler-text-{{ md5 $text }}">{{ $text | markdownify }}</label></s> +<s title="{{ $title }}"> + <label>{{ $text | markdownify }}</label> +</s> |