theme: make expand and image ids stable #477

This commit is contained in:
Sören Weber 2023-02-13 23:21:23 +01:00
parent 09e7aebcd8
commit e7a0ef9d9e
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
4 changed files with 11 additions and 2 deletions

View file

@ -1,6 +1,14 @@
{{- $version := split hugo.Version "." }}
{{- $major := int (index $version 0) }}
{{- $minor := int (index $version 1) }}
{{- $id := "" }}
{{- if and (ge $major 0) (ge $major 108) }}
{{- $id = .Ordinal }}
{{- end }}
{{- partial "shortcodes/image.html" (dict
"context" .Page
"url" .Destination
"title" .Title
"alt" .Text
"id" $id
) }}

View file

@ -6,8 +6,8 @@
{{- 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 }}
{{- with $context }}
{{- $id := partial "make-random-md5.hugo" }}
<div class="expand">
<input type="checkbox" id="expand-{{ $id }}" aria-controls="expandcontent-{{ $id }}" {{ if $expanded }} checked{{ end }}>
<label class="expand-label" for="expand-{{ $id }}" >

View file

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

View file

@ -4,4 +4,5 @@
"content" .Inner
"open" (.Get "open" | default (.Get 1))
"title" (.Get "title" | default (.Get 0))
"id" .Ordinal
) }}