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
All checks were successful
/ build (pull_request) Successful in 27s
This commit is contained in:
parent
a3978700b3
commit
14aed5e649
15 changed files with 1433 additions and 2 deletions
10
layouts/_partials/tour-map-script.html
Normal file
10
layouts/_partials/tour-map-script.html
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{{- /* Leaflet and the script for the tour-map shortcode, included by the base templates on pages that use it. */ -}}
|
||||
{{- with resources.Get "vendor/leaflet/leaflet.css" | fingerprint }}
|
||||
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
|
||||
{{- end }}
|
||||
{{- with resources.Get "vendor/leaflet/leaflet.js" | fingerprint }}
|
||||
<script src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous" defer></script>
|
||||
{{- end }}
|
||||
{{- with resources.Get "js/tour-map.js" | minify | fingerprint }}
|
||||
<script src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous" defer></script>
|
||||
{{- end }}
|
||||
70
layouts/_shortcodes/tour-map.html
Normal file
70
layouts/_shortcodes/tour-map.html
Normal 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 }}&mlon={{ .lon }}#map=17/{{ .lat }}/{{ .lon }}">{{ i18n "tour_map_osm" }}</a>)
|
||||
{{- with .directions }}{{ . }}{{ end }}
|
||||
</li>
|
||||
{{- end }}
|
||||
</ul>
|
||||
</div>
|
||||
{{- end -}}
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
{{ partial "head/extra.html" . }}
|
||||
{{ block "head" . }}{{ end }}
|
||||
{{ if .HasShortcode "schedule" }}{{ partial "schedule-script.html" . }}{{ end }}
|
||||
{{ if .HasShortcode "tour-map" }}{{ partial "tour-map-script.html" . }}{{ end }}
|
||||
</head>
|
||||
|
||||
<body class="{{ if .IsPage }}single-page{{ else }}list-page{{ end }}{{ if .IsHome }} front{{ end }}{{ with .Section }} section-page--{{ . | urlize }}{{ end }}{{ with $.Param "bodyclass" }} {{ . }}{{ end }}">
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
{{ partial "head/extra.html" . }}
|
||||
{{ block "head" . }}{{ end }}
|
||||
{{ if .HasShortcode "schedule" }}{{ partial "schedule-script.html" . }}{{ end }}
|
||||
{{ if .HasShortcode "tour-map" }}{{ partial "tour-map-script.html" . }}{{ end }}
|
||||
</head>
|
||||
|
||||
<body class="{{ if .IsPage }}single-page{{ else }}list-page{{ end }}{{ if .IsHome }} front{{ end }}{{ with .Section }} section-page--{{ . | urlize }}{{ end }}{{ with $.Param "bodyclass" }} {{ . }}{{ end }}">
|
||||
|
|
|
|||
Loading…
Reference in a new issue