From 8244189497e285fef6fcc0ec5e142cd81820a610 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Tue, 14 Jul 2026 02:22:03 +0000 Subject: [PATCH 1/2] - replaced the PROD-based ternary with a BUILD_ENV env var (local / staging / production) read via process.env (not import.meta.env Unknown values throw a clear error. staging resolves to https://genesis76.com/tech-docs, production to https://system76.com/tech-docs, unset/local to http://localhost:4321/tech-docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - set BUILD_ENV: staging / BUILD_ENV: production on the pnpm build step. CI's build step (ci.yml) is left without BUILD_ENV, so it defaults to local — fine since it only checks the build succeeds. --- .github/workflows/deploy-prod.yml | 2 ++ .github/workflows/deploy-staging.yml | 2 ++ astro.config.mjs | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index f37e08b7..75755889 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -39,6 +39,8 @@ jobs: - name: Build run: pnpm build + env: + BUILD_ENV: production - name: Save cache to S3 run: | diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 4d701cd0..03fb4b39 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -39,6 +39,8 @@ jobs: - name: Build run: pnpm build + env: + BUILD_ENV: staging # - name: Save cache to S3 # run: | diff --git a/astro.config.mjs b/astro.config.mjs index 6b60c9fe..b2a44b94 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -11,9 +11,21 @@ import { generateSidebar } from "./src/plugins/summary-to-sidebar.ts"; const base = "tech-docs"; -const site = import.meta.env.PROD - ? `https://system76.com/${base}` - : `http://localhost:4321/${base}`; +const buildEnv = process.env.BUILD_ENV ?? "local"; + +const siteByBuildEnv = { + local: `http://localhost:4321/${base}`, + staging: `https://genesis76.com/${base}`, + production: `https://system76.com/${base}`, +}; + +if (!(buildEnv in siteByBuildEnv)) { + throw new Error( + `Invalid BUILD_ENV "${buildEnv}", expected one of: ${Object.keys(siteByBuildEnv).join(", ")}`, + ); +} + +const site = siteByBuildEnv[/** @type {keyof typeof siteByBuildEnv} */ (buildEnv)]; // https://astro.build/config export default defineConfig({ From cdd4bc918552612dfffefb0ea9c40553fd98fa39 Mon Sep 17 00:00:00 2001 From: Erin O'Connell Date: Tue, 14 Jul 2026 03:42:48 +0000 Subject: [PATCH 2/2] -Add Google Analytics via Starlight's head config, gated on a new BUILD_ENV variable (local/staging/production); -convert astro.config.mjs to astro.config.ts. --- astro.config.mjs => astro.config.ts | 30 +++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) rename astro.config.mjs => astro.config.ts (84%) diff --git a/astro.config.mjs b/astro.config.ts similarity index 84% rename from astro.config.mjs rename to astro.config.ts index b2a44b94..007b6e8b 100644 --- a/astro.config.mjs +++ b/astro.config.ts @@ -1,6 +1,6 @@ -// @ts-check import { satteri } from "@astrojs/markdown-satteri"; import starlight from "@astrojs/starlight"; +import type { StarlightConfig } from "@astrojs/starlight/types"; import { defineConfig, fontProviders } from "astro/config"; import { satteriRelativeMarkdownLinks } from "@system76/satteri-relative-markdown-links"; @@ -9,6 +9,8 @@ import { viteStaticCopy } from "vite-plugin-static-copy"; import wrapImagesWithOriginals from "./src/plugins/satteri-wrap-images-with-originals.ts"; import { generateSidebar } from "./src/plugins/summary-to-sidebar.ts"; +type HeadConfig = NonNullable[number]; + const base = "tech-docs"; const buildEnv = process.env.BUILD_ENV ?? "local"; @@ -25,7 +27,30 @@ if (!(buildEnv in siteByBuildEnv)) { ); } -const site = siteByBuildEnv[/** @type {keyof typeof siteByBuildEnv} */ (buildEnv)]; +function googleAnalyticsHead(): HeadConfig[] { + if (buildEnv !== "production") { + return []; + } + + return [ + { + tag: "script", + attrs: { + async: true, + src: "https://www.googletagmanager.com/gtag/js?id=G-H37KSF3165", + }, + }, + { + tag: "script", + content: `window.dataLayer = window.dataLayer || []; + function gtag() { dataLayer.push(arguments); } + gtag('js', new Date()); + gtag('config', 'G-H37KSF3165');`, + }, + ]; +} + +const site = siteByBuildEnv[buildEnv as keyof typeof siteByBuildEnv]; // https://astro.build/config export default defineConfig({ @@ -80,6 +105,7 @@ export default defineConfig({ components: { Head: "./src/components/Head.astro", }, + head: [...googleAnalyticsHead()], }), ], base,