From f3746e0fc44152bbee343da54a75a97b3c8feae8 Mon Sep 17 00:00:00 2001 From: Martin Rubli Date: Mon, 18 Dec 2023 23:11:59 +0100 Subject: [PATCH] layouts: map: Make unique ID unique on page, not only shortcut parent The SHORTCODE.Ordinal method "returns the zero-based ordinal of the shortcode in relation to its parent." (https://gohugo.io/methods/shortcode/ordinal/) This is a problem if the same shortcode is used on the different page through different paths, e.g. once on the page itself and once by a partial (e.g. a header or footer). Instead of just using the .Ordinal by itself, use a hash of the parent file _and_ the ordinal, which gives us a properly unique identifier. --- layouts/shortcodes/leaflet-elevation-profile.html | 2 +- layouts/shortcodes/leaflet-layer.html | 2 +- layouts/shortcodes/leaflet-map.html | 2 +- layouts/shortcodes/leaflet-marker.html | 2 +- layouts/shortcodes/leaflet-scale.html | 2 +- layouts/shortcodes/leaflet-track.html | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/layouts/shortcodes/leaflet-elevation-profile.html b/layouts/shortcodes/leaflet-elevation-profile.html index a2a8980..7f1780a 100644 --- a/layouts/shortcodes/leaflet-elevation-profile.html +++ b/layouts/shortcodes/leaflet-elevation-profile.html @@ -2,7 +2,7 @@ {{ errorf "%s: cannot be used outside leaflet-map: %s" .Name .Position }} {{ end }} -{{ $uniqueMapId := .Parent.Ordinal | safeJS }} +{{ $uniqueMapId := (printf "%s:%d" .Page.File.UniqueID .Parent.Ordinal) | md5 | safeJS }}