use partial for footer scripts

This commit is contained in:
Ben Goldsworthy 2025-06-04 17:54:51 +02:00
parent 7f421830c5
commit ed9e769b2d
No known key found for this signature in database
5 changed files with 125 additions and 78 deletions

View file

@ -30,48 +30,11 @@
{{ end }}
{{ define "footer-scripts" }}
{{ with .Params.locations }}
<script>
var map = L.map('map').setView([55, -3], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
var latLons = [];
{{ $locations := partialCached "util/get_location_leaf_nodes.html" $.Site.Data.locations -}}
{{- range . -}}
{{- with ( index $locations ( replaceRE `, [A-Z]+` "" . ) ) -}}
L.marker([{{ .lat }}, {{ .lon }}]).addTo(map);
latLons.push([{{ .lat }}, {{ .lon }}]);
{{- else -}}
{{- erroridf "missing-lat-lon" "Could not find lat-lon for %q (%q)" . $.File.Path -}}
{{- end -}}
{{- end }}
map.fitBounds(latLons);
if (map.getZoom() < 10) map.setZoom(10);
</script>
{{ end }}
{{ if $.HasShortcode "chart" }}
{{ $chartsConfigJS := $.Page.Resources.GetMatch "charts-init" | fingerprint }}
<script
id="Charts-script"
src="/js/chart/chart.js"
></script>
<script src="/js/chartjs-plugin-annotation/dist/chartjs-plugin-annotation.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
<script
id="Charts-config-script"
src="{{ $chartsConfigJS.Permalink }}"
integrity="{{ $chartsConfigJS.Data.Integrity }}"
></script>
{{ end }}
{{- partialCached "single/footer-scripts.html" ( dict "pc" . "sc" $ ) . -}}
{{ end }}
{{ define "main-header" }}
{{ partial "single/main-header.html" ( dict "pc" . "sc" $ ) }}
{{- partial "single/main-header.html" ( dict "pc" . "sc" $ ) -}}
{{ end }}
{{ define "main-body" }}