mirror of
https://gitlab.com/mrubli/hugo-mod-leaflet.git
synced 2025-10-07 01:54:24 +00:00
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.
This commit is contained in:
@@ -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 }}
|
||||
|
||||
<script>
|
||||
map_options_{{ $uniqueMapId }}.heightgraph = {
|
||||
|
@@ -6,7 +6,7 @@
|
||||
{{ errorf "%s: missing 'id' parameter: %s" .Name .Position }}
|
||||
{{ end }}
|
||||
|
||||
{{ $uniqueMapId := .Parent.Ordinal | safeJS }}
|
||||
{{ $uniqueMapId := (printf "%s:%d" .Page.File.UniqueID .Parent.Ordinal) | md5 | safeJS }}
|
||||
|
||||
{{ $id := .Get "id" }}
|
||||
<script>
|
||||
|
@@ -119,7 +119,7 @@ Elevation profile options:
|
||||
|
||||
*/}}
|
||||
|
||||
{{ $uniqueId := .Ordinal | safeJS }}
|
||||
{{ $uniqueId := (printf "%s:%d" .Page.File.UniqueID .Ordinal) | md5 | safeJS }}
|
||||
|
||||
<div id="map_container_{{ $uniqueId }}" class="map-container" style="width: {{ .Get "width" | default "auto" }}; height: {{ .Get "height" | default "50vh" }};">
|
||||
<div id="map_{{ $uniqueId }}" class="map"></div>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
{{ errorf "%s: missing 'lon' parameter: %s" .Name .Position }}
|
||||
{{ end }}
|
||||
|
||||
{{ $uniqueMapId := .Parent.Ordinal | safeJS }}
|
||||
{{ $uniqueMapId := (printf "%s:%d" .Page.File.UniqueID .Parent.Ordinal) | md5 | safeJS }}
|
||||
|
||||
<script>
|
||||
map_options_{{ $uniqueMapId }}.markers.push({ lat: {{ .Get "lat" }}, lon: {{ .Get "lon" }} })
|
||||
|
@@ -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 }}
|
||||
|
||||
<script>
|
||||
map_options_{{ $uniqueMapId }}.scale = {
|
||||
|
@@ -6,7 +6,7 @@
|
||||
{{ errorf "%s: missing 'path' parameter: %s" .Name .Position }}
|
||||
{{ end }}
|
||||
|
||||
{{ $uniqueMapId := .Parent.Ordinal | safeJS }}
|
||||
{{ $uniqueMapId := (printf "%s:%d" .Page.File.UniqueID .Parent.Ordinal) | md5 | safeJS }}
|
||||
|
||||
<script>
|
||||
map_options_{{ $uniqueMapId }}.tracks.push({{ .Get "path" }})
|
||||
|
Reference in New Issue
Block a user