cache images w/ map shortcode - apiKey can now be priv again

This commit is contained in:
Jakub 2024-02-05 23:24:17 -05:00
parent 4e7f19f5b3
commit dcc0dd02b4

View File

@ -1,26 +1,47 @@
{{/* Required params. Fail if missing. */}}
<div class="location" >
<link rel="stylesheet" href="{{ "/css/maps.css" | relURL }}" />
<div class="map" >
{{ $apiKey := .Site.Params.apiKey }} {{ $apiKey := .Site.Params.apiKey }}
{{ if not $apiKey }}
{{ errorf "Error: 'apiKey' is a required site parameter for this shortcode." }}
{{ end }}
{{ $adr := .Get "address" }}
{{ if not $adr }}
{{ errorf "Error: 'address' is a required parameter for this shortcode." }}
{{ end }}
{{ $path := .Get "path" }}
{{ if not $path }}
{{ errorf "Error: 'path' is a required parameter for this shortcode." }}
{{ end }}
{{/* Optional params. No error checking. */}}
{{ $label := .Get "label" }} {{ $label := .Get "label" }}
{{ $url := .Get "url" }} {{ $url := .Get "url" }}
{{ $adr := .Get "address" }}
{{ $adrURL := urlquery $adr }}
{{ $LLapiURL := printf "https://api.geoapify.com/v1/geocode/search?text=%s&format=json&apiKey=%s" $adrURL $apiKey }}
{{ $adrURL := urlquery $adr }}
{{ $LLapiURL := printf "https://api.geoapify.com/v1/geocode/search?text=%s&format=json&apiKey=%s" $adrURL $apiKey }}
{{ $data := getJSON $LLapiURL }} {{ $data := getJSON $LLapiURL }}
{{ with index $data.results 0 }} {{ with index $data.results 0 }}
{{ $lon := .lon }} {{ $lon := .lon }}
{{ $lat := .lat }} {{ $lat := .lat }}
{{ $MapApiUrl := printf "https://maps.geoapify.com/v1/staticmap?style=osm-bright&width=500&height=500&center=lonlat:%f,%f&zoom=12&marker=lonlat:%f,%f;color:%%23ff0000;size:medium&scaleFactor=2&apiKey=%s" $lon $lat $lon $lat $apiKey }} {{ $MapApiUrl := printf "https://maps.geoapify.com/v1/staticmap?style=osm-bright&width=500&height=500&center=lonlat:%f,%f&zoom=12&marker=lonlat:%f,%f;color:%%23ff0000;size:medium&scaleFactor=2&apiKey=%s" $lon $lat $lon $lat $apiKey }}
<div class="location" >
<link rel="stylesheet" href="{{ "/css/maps.css" | relURL }}" />
<div class="map" >
{{ with resources.GetRemote $MapApiUrl }}
{{ with resources.Copy $path . }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
<img src="{{ .RelPermalink }}" width=350px />
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $MapApiUrl }}
{{ end }}
{{ end }}
<img src="{{ $MapApiUrl }}" width=350px />
<div class="map-txt-grid"> <div class="map-txt-grid">
<div class="grid-item"> <div class="grid-item">
{{ with $label }} {{ with $label }}