theme: make IDs stable for testing

This commit is contained in:
Sören Weber 2023-05-17 22:55:34 +02:00
parent 4bdbb9ea6a
commit 899cab1cf6
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
5 changed files with 16 additions and 10 deletions

View file

@ -3,6 +3,7 @@ set /p version=<..\layouts\partials\version.txt
echo %version%>metrics.%version%.txt
echo disableAssetsBusting=true>>config.toml
echo disableGeneratorVersion=true>>config.toml
echo disableRandomIds=true>>config.toml
hugo --templateMetrics --templateMetricsHints --cleanDestinationDir --destination public.%version% >> metrics.%version%.txt
move /Y metrics.%version%.txt public.%version%\metrics.txt 2>&1 >NUL
git restore config.toml

View file

@ -1,8 +1,13 @@
{{- $random := "" }}
{{- $set := split "012345abcdefghijklmnopqrstuvwxyz" "" }}
{{- range (seq 16) }}
{{- $context := . }}
{{- if (ne $context.Site.Params.disableRandomIds true) }}
{{- $random := "" }}
{{- $set := split "012345abcdefghijklmnopqrstuvwxyz" "" }}
{{- range (seq 16) }}
{{- with ($set | shuffle | first 1) }}
{{- $random = printf "%s%s" $random . }}
{{- end }}
{{- end }}
{{- md5 $random }}
{{- else }}
{{- printf "00000000000000000000000000000000" }}
{{- end }}
{{- md5 $random }}

View file

@ -6,7 +6,7 @@
{{- if eq (printf "%T" $expanded) "string" }}
{{- $expanded = (eq $expanded "true") }}
{{- end }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo") .id }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $context.Page) .id }}
{{- with $context }}
<div class="expand">
<input type="checkbox" id="expand-{{ $id }}" aria-controls="expandcontent-{{ $id }}" {{ if $expanded }} checked{{ end }}>

View file

@ -33,7 +33,7 @@
{{ $width = . }}
{{- end }}
{{- end }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo") .id }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $context) .id }}
{{- if $lightbox }}
<a href="#image-{{ $id }}" class="lightbox-link">
{{- end }}

View file

@ -1,6 +1,6 @@
{{- $context := .context }}
{{- $src := .src }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo") .id }}
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $context.Page) .id }}
{{- with $context }}
{{- with .Page.Resources.Match $src }}
{{- range . }}