From 8113e9c39376d1e9fb1c239a678a7502272e8fda Mon Sep 17 00:00:00 2001 From: tdro Date: Mon, 21 Nov 2022 11:23:56 -0500 Subject: themes/default/layouts: Use hashing algorithm consistently Avoid using shuffle in short codes by appending .Ordinal value --- themes/default/layouts/_default/_markup/render-codeblock.html | 5 +++-- themes/default/layouts/_default/index.json | 2 +- themes/default/layouts/partials/card-id.html | 2 +- themes/default/layouts/partials/meta-context-menu.html | 2 +- themes/default/layouts/shortcodes/abbr.html | 6 +++--- themes/default/layouts/shortcodes/spoiler.html | 8 ++++++-- themes/default/layouts/shortcodes/spoiler.rss.xml | 4 +++- 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 -}}
@@ -13,7 +14,7 @@ Copy
- {{ highlight .Inner $type (print $options ",lineAnchors=" "code-line-" (truncate 7 "" (md5 .Inner))) }} + {{ highlight .Inner $type (print $options ",lineAnchors=" "code-line-" $hash) }}
{{ 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)) "" -}} - + {{- /* This comment removes trailing newlines and white spaces. */ -}} - + {{- /* 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 -}} - - + + + + + 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 }} - + + + -- cgit v1.2.3