diff --git a/layouts/shortcodes/maps.html b/layouts/shortcodes/maps.html index 3959716..89d2726 100644 --- a/layouts/shortcodes/maps.html +++ b/layouts/shortcodes/maps.html @@ -1,26 +1,47 @@ +{{/* Required params. Fail if missing. */}} - - - - - -
- -
{{ $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" }} {{ $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 }} {{ with index $data.results 0 }} {{ $lon := .lon }} {{ $lat := .lat }} {{ $MapApiUrl := printf "https://maps.geoapify.com/v1/staticmap?style=osm-bright&width=500&height=500¢er=lonlat:%f,%f&zoom=12&marker=lonlat:%f,%f;color:%%23ff0000;size:medium&scaleFactor=2&apiKey=%s" $lon $lat $lon $lat $apiKey }} +
+ +
+ {{ with resources.GetRemote $MapApiUrl }} + {{ with resources.Copy $path . }} + {{ with .Err }} + {{ errorf "%s" . }} + {{ else }} + + {{ end }} + {{ else }} + {{ errorf "Unable to get remote resource %q" $MapApiUrl }} + {{ end }} + {{ end }} -
{{ with $label }}