From 4cfa9f340a3250386116e641ec2e11beb28d26d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kuna?= <1282324+codecalm@users.noreply.github.com> Date: Fri, 18 Sep 2026 14:51:26 +0200 Subject: [PATCH] Read the map keys from `GOOGLE_MAPS_KEY` and `MAPBOX_KEY` instead of the source (#3092) --- .changeset/google-maps-key-env.md | 5 +++++ .gitignore | 1 + preview/.env.example | 7 +++++++ shared/components/demo/Map.astro | 13 ++++++++----- shared/data/site.json | 3 --- shared/layouts/BaseLayout.astro | 6 ++++-- shared/lib/site.ts | 2 -- turbo.json | 2 +- 8 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 .changeset/google-maps-key-env.md create mode 100644 preview/.env.example diff --git a/.changeset/google-maps-key-env.md b/.changeset/google-maps-key-env.md new file mode 100644 index 000000000..5a05c666b --- /dev/null +++ b/.changeset/google-maps-key-env.md @@ -0,0 +1,5 @@ +--- +"@tabler/preview": patch +--- + +Removed the hardcoded Google Maps and Mapbox keys; map demos now read `GOOGLE_MAPS_KEY` and `MAPBOX_KEY` from the environment. diff --git a/.gitignore b/.gitignore index 90689d77c..de2a85bba 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ package-lock.json dist/ packages-zip/ .env +.env*.local sri.json # TypeScript diff --git a/preview/.env.example b/preview/.env.example new file mode 100644 index 000000000..620d7117e --- /dev/null +++ b/preview/.env.example @@ -0,0 +1,7 @@ +# Google Maps JavaScript API key for the map demo page (map-fullsize). +# Optional. Restrict the key by HTTP referrer in the Google Cloud console. +GOOGLE_MAPS_KEY= + +# Mapbox public access token (pk.…) for the Mapbox GL map demos. +# Optional. Restrict the token by URL in the Mapbox account settings. +MAPBOX_KEY= diff --git a/shared/components/demo/Map.astro b/shared/components/demo/Map.astro index 405144bf8..f402838e2 100644 --- a/shared/components/demo/Map.astro +++ b/shared/components/demo/Map.astro @@ -1,8 +1,9 @@ --- -// Mapbox GL map. Access token from site.mapboxKey. Renders nothing unless -// maps[mapId] exists. +// Mapbox GL map. Access token from the MAPBOX_KEY environment variable (.env or +// the host's settings), never from the source. Renders nothing unless +// maps[mapId] exists; without a token the container renders but the map is not +// initialised (Mapbox GL throws on a missing token). import maps from '@data/maps.json'; -import site from '@data/site.json'; import CaptureScript from '../CaptureScript.astro'; interface Props { @@ -13,6 +14,8 @@ interface Props { const { mapId, ratio } = Astro.props; +const mapboxKey = import.meta.env.MAPBOX_KEY ?? process.env.MAPBOX_KEY ?? ''; + type MapData = { title?: string; ratio?: string; @@ -44,10 +47,10 @@ const ratioClass = data?.ratio ?? ratio ?? '16x9'; ) } { - data && ( + data && mapboxKey && ( -