From e7a0ef9d9ebd7d94af95548e9d28632c22881eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Mon, 13 Feb 2023 23:21:23 +0100 Subject: [PATCH] theme: make expand and image ids stable #477 --- layouts/_default/_markup/render-image.html | 8 ++++++++ layouts/partials/shortcodes/expand.html | 2 +- layouts/partials/shortcodes/image.html | 2 +- layouts/shortcodes/expand.html | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 500fc908ed..0bda2dd528 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -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 ) }} \ No newline at end of file diff --git a/layouts/partials/shortcodes/expand.html b/layouts/partials/shortcodes/expand.html index a5c29ccd0b..d9132e3907 100644 --- a/layouts/partials/shortcodes/expand.html +++ b/layouts/partials/shortcodes/expand.html @@ -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" }}