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 %version%>metrics.%version%.txt
echo disableAssetsBusting=true>>config.toml echo disableAssetsBusting=true>>config.toml
echo disableGeneratorVersion=true>>config.toml echo disableGeneratorVersion=true>>config.toml
echo disableRandomIds=true>>config.toml
hugo --templateMetrics --templateMetricsHints --cleanDestinationDir --destination public.%version% >> metrics.%version%.txt hugo --templateMetrics --templateMetricsHints --cleanDestinationDir --destination public.%version% >> metrics.%version%.txt
move /Y metrics.%version%.txt public.%version%\metrics.txt 2>&1 >NUL move /Y metrics.%version%.txt public.%version%\metrics.txt 2>&1 >NUL
git restore config.toml git restore config.toml

View file

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

View file

@ -6,7 +6,7 @@
{{- if eq (printf "%T" $expanded) "string" }} {{- if eq (printf "%T" $expanded) "string" }}
{{- $expanded = (eq $expanded "true") }} {{- $expanded = (eq $expanded "true") }}
{{- 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.Page) .id }}
{{- with $context }} {{- with $context }}
<div class="expand"> <div class="expand">
<input type="checkbox" id="expand-{{ $id }}" aria-controls="expandcontent-{{ $id }}" {{ if $expanded }} checked{{ end }}> <input type="checkbox" id="expand-{{ $id }}" aria-controls="expandcontent-{{ $id }}" {{ if $expanded }} checked{{ end }}>

View file

@ -33,7 +33,7 @@
{{ $width = . }} {{ $width = . }}
{{- end }} {{- end }}
{{- 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 }} {{- if $lightbox }}
<a href="#image-{{ $id }}" class="lightbox-link"> <a href="#image-{{ $id }}" class="lightbox-link">
{{- end }} {{- end }}

View file

@ -1,6 +1,6 @@
{{- $context := .context }} {{- $context := .context }}
{{- $src := .src }} {{- $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 $context }}
{{- with .Page.Resources.Match $src }} {{- with .Page.Resources.Match $src }}
{{- range . }} {{- range . }}