Skip to content

Commit 899cab1

Browse files
committed
theme: make IDs stable for testing
1 parent 4bdbb9e commit 899cab1

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

exampleSite/test.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set /p version=<..\layouts\partials\version.txt
33
echo %version%>metrics.%version%.txt
44
echo disableAssetsBusting=true>>config.toml
55
echo disableGeneratorVersion=true>>config.toml
6+
echo disableRandomIds=true>>config.toml
67
hugo --templateMetrics --templateMetricsHints --cleanDestinationDir --destination public.%version% >> metrics.%version%.txt
78
move /Y metrics.%version%.txt public.%version%\metrics.txt 2>&1 >NUL
89
git restore config.toml
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
{{- $random := "" }}
2-
{{- $set := split "012345abcdefghijklmnopqrstuvwxyz" "" }}
3-
{{- range (seq 16) }}
4-
{{- with ($set | shuffle | first 1) }}
5-
{{- $random = printf "%s%s" $random . }}
1+
{{- $context := . }}
2+
{{- if (ne $context.Site.Params.disableRandomIds true) }}
3+
{{- $random := "" }}
4+
{{- $set := split "012345abcdefghijklmnopqrstuvwxyz" "" }}
5+
{{- range (seq 16) }}
6+
{{- with ($set | shuffle | first 1) }}
7+
{{- $random = printf "%s%s" $random . }}
8+
{{- end }}
69
{{- end }}
7-
{{- end }}
8-
{{- md5 $random }}
10+
{{- md5 $random }}
11+
{{- else }}
12+
{{- printf "00000000000000000000000000000000" }}
13+
{{- end }}

layouts/partials/shortcodes/expand.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{{- if eq (printf "%T" $expanded) "string" }}
77
{{- $expanded = (eq $expanded "true") }}
88
{{- end }}
9-
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo") .id }}
9+
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $context.Page) .id }}
1010
{{- with $context }}
1111
<div class="expand">
1212
<input type="checkbox" id="expand-{{ $id }}" aria-controls="expandcontent-{{ $id }}" {{ if $expanded }} checked{{ end }}>

layouts/partials/shortcodes/image.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
{{ $width = . }}
3434
{{- end }}
3535
{{- end }}
36-
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo") .id }}
36+
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $context) .id }}
3737
{{- if $lightbox }}
3838
<a href="#image-{{ $id }}" class="lightbox-link">
3939
{{- end }}

layouts/partials/shortcodes/openapi.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- $context := .context }}
22
{{- $src := .src }}
3-
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo") .id }}
3+
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $context.Page) .id }}
44
{{- with $context }}
55
{{- with .Page.Resources.Match $src }}
66
{{- range . }}

0 commit comments

Comments
 (0)