mirror of
https://gitlab.com/mrubli/hugo-mod-leaflet.git
synced 2025-10-17 23:13:12 +00:00

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.
34 lines
811 B
HTML
34 lines
811 B
HTML
{{ if or (not .Parent) (not (eq .Parent.Name "leaflet-map")) }}
|
|
{{ errorf "%s: cannot be used outside leaflet-map: %s" .Name .Position }}
|
|
{{ end }}
|
|
|
|
{{ $uniqueMapId := (printf "%s:%d" .Page.File.UniqueID .Parent.Ordinal) | md5 | safeJS }}
|
|
|
|
<script>
|
|
map_options_{{ $uniqueMapId }}.heightgraph = {
|
|
enabled: true,
|
|
expanded: {{ .Get "expanded" | default "false" }},
|
|
{{ with .Get "resizable" }}
|
|
resizable: {{ . }},
|
|
{{ end }}
|
|
{{ with .Get "width" }}
|
|
width: {{ . }},
|
|
{{ end }}
|
|
{{ with .Get "height" }}
|
|
height: {{ . }},
|
|
{{ end }}
|
|
{{ with .Get "minWidth" }}
|
|
minWidth: {{ . }},
|
|
{{ end }}
|
|
{{ with .Get "minHeight" }}
|
|
minHeight: {{ . }},
|
|
{{ end }}
|
|
{{ with .Get "maxWidth" }}
|
|
maxWidth: {{ . }},
|
|
{{ end }}
|
|
{{ with .Get "maxHeight" }}
|
|
maxHeight: {{ . }},
|
|
{{ end }}
|
|
};
|
|
</script>
|