use partial for footer scripts
This commit is contained in:
parent
7f421830c5
commit
ed9e769b2d
5 changed files with 125 additions and 78 deletions
30
layouts/partials/scripts/charts.html
Normal file
30
layouts/partials/scripts/charts.html
Normal file
|
@ -0,0 +1,30 @@
|
|||
{{- /*
|
||||
Renders charts on a post.
|
||||
|
||||
@params . Chart JS config script.
|
||||
*/
|
||||
-}}
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not . ) -}}
|
||||
{{- errorf "No config JS defined" -}}
|
||||
{{- end -}}
|
||||
|
||||
<!-- Variable Assignment -->
|
||||
|
||||
{{- $chartsConfigJS := . -}}
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<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>
|
46
layouts/partials/scripts/show_post_locations_on_map.html
Normal file
46
layouts/partials/scripts/show_post_locations_on_map.html
Normal file
|
@ -0,0 +1,46 @@
|
|||
{{- /*
|
||||
Renders a post's locations on a map.
|
||||
|
||||
@params pc Page context.
|
||||
@params locations_data Site data of locations.
|
||||
@params locations Post locations.
|
||||
*/
|
||||
-}}
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset . "pc" ) ) -}}
|
||||
{{- errorf "No page context passed" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "locations_data" ) ) -}}
|
||||
{{- errorf "No location site data defined" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "locations" ) ) -}}
|
||||
{{- errorf "No post locations defined" -}}
|
||||
{{- end -}}
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<script>
|
||||
var map = L.map('map').setView([55, -3], 13);
|
||||
|
||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
maxZoom: 19,
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
||||
}).addTo(map);
|
||||
|
||||
var latLons = [];
|
||||
{{ $locations_leaf_nodes := partialCached "util/get_location_leaf_nodes.html" .locations_data -}}
|
||||
{{- range .locations -}}
|
||||
{{- with ( index $locations_leaf_nodes ( 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" . -}}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
|
||||
map.fitBounds(latLons);
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue