Add a generic tour-map shortcode and a data format to supply the necessary info
All checks were successful
/ build (pull_request) Successful in 27s

This commit is contained in:
Stefan Bethke 2026-10-16 20:21:21 +02:00
commit 14aed5e649
15 changed files with 1433 additions and 2 deletions

View file

@ -0,0 +1,70 @@
{{- /*
Map of an event's tour locations with routes from the Congress, on OpenStreetMap tiles.
Reads the map and tours sections of data/schedule/<event>.yaml (format in README.md).
Without JavaScript it shows a list of the locations with links to OpenStreetMap.
Usage: {{< tour-map >}} on a section page (the event is the section name),
or {{< tour-map 39c3 >}}.
*/ -}}
{{- $event := .Get 0 | default .Page.Section -}}
{{- $lang := .Page.Language.Name -}}
{{- $other := cond (eq $lang "de") "en" "de" -}}
{{- $data := dict -}}
{{- with hugo.Data.schedule }}{{ with index . $event }}{{ $data = . }}{{ end }}{{ end -}}
{{- /* Tour page titles start with the event name ("39C3 Rote Flora"); the map doesn't need it. */ -}}
{{- $prefix := printf `(?i)^%s\s+` $event -}}
{{- $tours := slice -}}
{{- range $slug, $tour := $data.tours -}}
{{- with $tour.geo -}}
{{- $title := $slug -}}
{{- $url := "" -}}
{{- with $.Page.GetPage $slug -}}
{{- $title = .LinkTitle | replaceRE $prefix "" -}}
{{- $url = .RelPermalink -}}
{{- else -}}
{{- warnf "tour-map: %s: no page for tour %q" $event $slug -}}
{{- end -}}
{{- $directions := "" -}}
{{- with $tour.directions -}}
{{- with index . $lang | default (index . $other) -}}
{{- $directions = $.Page.RenderString (dict "display" "block") . -}}
{{- end -}}
{{- end -}}
{{- $tours = $tours | append (dict
"title" $title
"url" $url
"lat" .lat
"lon" .lon
"color" ($tour.color | default "")
"icon" ($tour.icon | default "")
"directions" $directions
"route" ($tour.route | default slice)
) -}}
{{- end -}}
{{- end -}}
{{- $origin := dict -}}
{{- with $data.map }}{{ with .origin }}{{ with .geo -}}
{{- $name := "" -}}
{{- with $data.map.origin.name }}{{ $name = index . $lang | default (index . $other) }}{{ end -}}
{{- $origin = dict "name" $name "lat" .lat "lon" .lon "icon" ($data.map.origin.icon | default "") -}}
{{- end }}{{ end }}{{ end -}}
{{- if not $tours -}}
{{- warnidf "warning-tour-map-empty" "tour-map: no tours with geo in data/schedule/%s.yaml: %s" $event .Position -}}
{{- else -}}
{{- $tours = sort $tours "title" -}}
<div class="tour-map" data-tour-map="{{ jsonify (dict "origin" $origin "tours" $tours) }}">
<div class="tour-map__canvas" role="region" aria-label="{{ i18n "tour_map_label" }}"></div>
<ul class="tour-map__list">
{{- range $tours }}
<li>
{{- if .url }}<a href="{{ .url }}">{{ .title }}</a>{{ else }}{{ .title }}{{ end }}
(<a href="https://www.openstreetmap.org/?mlat={{ .lat }}&amp;mlon={{ .lon }}#map=17/{{ .lat }}/{{ .lon }}">{{ i18n "tour_map_osm" }}</a>)
{{- with .directions }}{{ . }}{{ end }}
</li>
{{- end }}
</ul>
</div>
{{- end -}}