aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2022-11-21 11:23:56 -0500
committertdro <tdro@noreply.example.com>2022-11-21 11:23:56 -0500
commit8113e9c39376d1e9fb1c239a678a7502272e8fda (patch)
treefc1e9263021d886db60a1b22d3cfee3b7bfa410d
parent4a82e6046ab0e8cf65a089a7b1e85c6ef918666c (diff)
downloadcanory-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
-rw-r--r--themes/default/layouts/_default/_markup/render-codeblock.html5
-rw-r--r--themes/default/layouts/_default/index.json2
-rw-r--r--themes/default/layouts/partials/card-id.html2
-rw-r--r--themes/default/layouts/partials/meta-context-menu.html2
-rw-r--r--themes/default/layouts/shortcodes/abbr.html6
-rw-r--r--themes/default/layouts/shortcodes/spoiler.html8
-rw-r--r--themes/default/layouts/shortcodes/spoiler.rss.xml4
7 files changed, 18 insertions, 11 deletions
diff --git a/themes/default/layouts/_default/_markup/render-codeblock.html b/themes/default/layouts/_default/_markup/render-codeblock.html
index 22d47e4..d629a85 100644
--- a/themes/default/layouts/_default/_markup/render-codeblock.html
+++ b/themes/default/layouts/_default/_markup/render-codeblock.html
@@ -1,7 +1,8 @@
{{- $caption := .Attributes.caption -}}
{{- $type := .Type | default "text" -}}
{{- $options := .Attributes.options | default "default=1" -}}
-{{- $id := print "code-block-" (truncate 7 "" (md5 .Inner)) -}}
+{{- $hash := print (truncate 8 "" (sha256 .Inner)) .Ordinal -}}
+{{- $id := print "code-block-" $hash -}}
<code-block id="{{ $id }}" {{ if in (lower $options) "linenos" }}data-lines{{ end }}>
<header>
@@ -13,7 +14,7 @@
<span>Copy</span>
</button>
</header>
- {{ highlight .Inner $type (print $options ",lineAnchors=" "code-line-" (truncate 7 "" (md5 .Inner))) }}
+ {{ highlight .Inner $type (print $options ",lineAnchors=" "code-line-" $hash) }}
</code-block>
{{ with $caption }}
diff --git a/themes/default/layouts/_default/index.json b/themes/default/layouts/_default/index.json
index 78c0fde..86641fa 100644
--- a/themes/default/layouts/_default/index.json
+++ b/themes/default/layouts/_default/index.json
@@ -13,7 +13,7 @@
{{- range $index, $data := $filteredPages -}}
{{- if and $index (gt $index 0) -}},{{- end }}
{
- "id": "{{ md5 $data.Permalink }}",
+ "id": "{{ sha256 $data.Permalink }}",
"url": "{{ $data.Permalink }}",
"title": "{{ $data.Summary | htmlUnescape }}",
"summary": "{{ $data.Summary | htmlUnescape }}",
diff --git a/themes/default/layouts/partials/card-id.html b/themes/default/layouts/partials/card-id.html
index 2675e90..b1ee3fc 100644
--- a/themes/default/layouts/partials/card-id.html
+++ b/themes/default/layouts/partials/card-id.html
@@ -2,6 +2,6 @@
{{- $relURL := strings.TrimPrefix .Page.Site.BaseURL .Page.Permalink -}}
{{- $source := urlize (humanize $relURL) -}}
{{- if .ExpiryDate -}}
- {{- $source = md5 $source -}}
+ {{- $source = truncate 8 "" (sha256 $source) -}}
{{- end -}}
{{- $source -}}
diff --git a/themes/default/layouts/partials/meta-context-menu.html b/themes/default/layouts/partials/meta-context-menu.html
index 79ffacc..98d47ec 100644
--- a/themes/default/layouts/partials/meta-context-menu.html
+++ b/themes/default/layouts/partials/meta-context-menu.html
@@ -1,4 +1,4 @@
-{{- $id := delimit (shuffle (seq 1 7)) "" -}}
+{{- $id := truncate 8 "" (sha256 .Content) -}}
{{- $author := partial "function-authors-data.html" . -}}
{{- $href := print .Permalink -}}
{{- $plain := print $href "index.txt" -}}
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>