diff --git a/.env b/.env new file mode 100644 index 0000000..3f2946c --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +VITE_QUEER_LEXIKON_PRIVATE=false + diff --git a/main.ts b/main.ts index 9839d18..206f5f5 100644 --- a/main.ts +++ b/main.ts @@ -5,6 +5,7 @@ import { initializeMap } from "./ts/map"; import "@fontsource/ubuntu/latin.css"; import { setupLegend } from "./ts/legend"; import { setupEmergencyButton } from "./ts/emergency-button"; +import { addGoatCounter } from "./ts/goatcounter"; document.addEventListener("DOMContentLoaded", () => { initializeMap(); @@ -12,4 +13,8 @@ document.addEventListener("DOMContentLoaded", () => { setupHamburger(); setupLegend(); setupEmergencyButton(); + + if (import.meta.env.VITE_QUEER_LEXIKON_PRIVATE === "true") { + addGoatCounter(); + } }); diff --git a/ts/env.d.ts b/ts/env.d.ts new file mode 100644 index 0000000..72cecca --- /dev/null +++ b/ts/env.d.ts @@ -0,0 +1,12 @@ +interface ImportMeta { + readonly env: ImportMetaEnv; +} +interface ImportMetaEnv { + // This variable is set in our GitHub Actions for adding additional features + // that should be only available on karte.queer-lexikon.net and not + // for development purposes. + // + // Although it's actually a boolean, all environment variables are strings, so we + // type it as string here as well. + readonly VITE_QUEER_LEXIKON_PRIVATE?: string; +} diff --git a/ts/goatcounter.ts b/ts/goatcounter.ts new file mode 100644 index 0000000..85a8d92 --- /dev/null +++ b/ts/goatcounter.ts @@ -0,0 +1,22 @@ +declare global { + interface Window { + goatcounter: { + path: (p: any) => string; + }; + } +} + +export const addGoatCounter = () => { + window.goatcounter = { + path: function (p: any) { + return location.host + p; + }, + }; + + let goatcounter = document.createElement("script"); + goatcounter.src = "//ziege.queer-lexikon.net/count.js"; + goatcounter.async = true; + goatcounter.setAttribute("data-goatcounter", "https://ziege.queer-lexikon.net/count"); + + document.head.appendChild(goatcounter); +}; diff --git a/tsconfig.json b/tsconfig.json index 583a677..b8ab2a2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "exclude": ["/dist"], "compilerOptions": { - "module": "ES2015", + "module": "ES2020", "strict": true, "lib": ["DOM", "ES2015"], "target": "ES2015",