mirror of
https://gitlab.com/mrubli/hugo-mod-leaflet.git
synced 2025-10-07 01:54:24 +00:00
layouts: layer: Allow retrieving API key from config
The config key name is the layer name with '.' replaced with '_'. For example: params: modules: leaflet: com_thunderforest_outdoors: apiKey: abcdef1234567890abcdef1234567890 If the key is specified in both the config file and the tag attribute, the latter takes precedence. Implements #6
This commit is contained in:
@@ -9,10 +9,12 @@
|
|||||||
{{ $uniqueMapId := (printf "%s:%d" .Page.File.UniqueID .Parent.Ordinal) | md5 | safeJS }}
|
{{ $uniqueMapId := (printf "%s:%d" .Page.File.UniqueID .Parent.Ordinal) | md5 | safeJS }}
|
||||||
|
|
||||||
{{ $id := .Get "id" }}
|
{{ $id := .Get "id" }}
|
||||||
|
{{ $configId := replace (.Get "id") "." "_" }}
|
||||||
|
{{ $apiKey := default (index .Site.Params.modules.leaflet $configId "apiKey") (.Get "apiKey") }}
|
||||||
<script>
|
<script>
|
||||||
map_options_{{ $uniqueMapId }}.layers.enabled.push({{ $id }});
|
map_options_{{ $uniqueMapId }}.layers.enabled.push({{ $id }});
|
||||||
map_options_{{ $uniqueMapId }}.layers["{{ $id }}"] = {
|
map_options_{{ $uniqueMapId }}.layers["{{ $id }}"] = {
|
||||||
{{ with .Get "apiKey" }}
|
{{ with $apiKey }}
|
||||||
apiKey: '{{ . }}',
|
apiKey: '{{ . }}',
|
||||||
{{ end }}
|
{{ end }}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user