hackertours/layouts/_shortcodes/tour-map.html

80 lines
3.2 KiB
HTML

{{- /*
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 -}}
{{- $icon := "" -}}
{{- with $tour.icon -}}
{{- $icon = partial "tour-map-icon.html" . -}}
{{- if not $icon }}{{ warnf "tour-map: %s: unknown icon %q for tour %q" $event . $slug }}{{ end -}}
{{- end -}}
{{- $tours = $tours | append (dict
"title" $title
"url" $url
"lat" .lat
"lon" .lon
"color" ($tour.color | default "")
"icon" $icon
"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 -}}
{{- $icon := "" -}}
{{- with $data.map.origin.icon -}}
{{- $icon = partial "tour-map-icon.html" . -}}
{{- if not $icon }}{{ warnf "tour-map: %s: unknown icon %q for the origin" $event . }}{{ end -}}
{{- end -}}
{{- $origin = dict "name" $name "lat" .lat "lon" .lon "icon" $icon -}}
{{- 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) }}" data-label-zoom-in="{{ i18n "tour_map_zoom_in" }}" data-label-zoom-out="{{ i18n "tour_map_zoom_out" }}">
<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 -}}