From 1383b7e6af7c6b7465b7c532e57fe7549e635f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Wed, 1 Feb 2023 23:16:42 +0100 Subject: [PATCH] lightbox: generate unique lightbox ids #451 --- layouts/_default/_markup/render-image.html | 1 - layouts/partials/make-random-md5.hugo | 8 ++++++++ layouts/partials/shortcodes/image.html | 7 +++---- 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 layouts/partials/make-random-md5.hugo diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index f7d656fa5a..500fc908ed 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -3,5 +3,4 @@ "url" .Destination "title" .Title "alt" .Text - "ordinal" 0 ) }} \ No newline at end of file diff --git a/layouts/partials/make-random-md5.hugo b/layouts/partials/make-random-md5.hugo new file mode 100644 index 0000000000..d355dde35d --- /dev/null +++ b/layouts/partials/make-random-md5.hugo @@ -0,0 +1,8 @@ +{{- $random := "" }} +{{- $set := split "012345abcdefghijklmnopqrstuvwxyz" "" }} +{{- range (seq 16) }} + {{- with ($set | shuffle | first 1) }} + {{- $random = printf "%s%s" $random . }} + {{- end }} +{{- end }} +{{- md5 $random }} \ No newline at end of file diff --git a/layouts/partials/shortcodes/image.html b/layouts/partials/shortcodes/image.html index 1807b8b00b..6b3aa9f291 100644 --- a/layouts/partials/shortcodes/image.html +++ b/layouts/partials/shortcodes/image.html @@ -2,7 +2,6 @@ {{- $url := .url }} {{- $title := .title }} {{- $alt := .alt }} -{{- $ordinal := .ordinal }} {{- $classes := slice }} {{- $lightbox := true }} {{- $height := "auto" }} @@ -34,14 +33,14 @@ {{ $width = . }} {{- end }} {{- end }} -{{- $fragment := printf "%d-%s" $ordinal ((trim (replace (replace (replace (replace (replace $url "=" "-") "&" "-") "?" "-") "." "-") "/" "-") "-") | safeURL | anchorize) }} +{{- $id := partial "make-random-md5.hugo" }} {{- if $lightbox }} - + {{- end }} {{ $alt }} {{- if $lightbox }} - + {{ $alt }} {{- end }} \ No newline at end of file