diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..8da9aeb --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +# Changelog API endpoint (GraphQL). REQUIRED — `pnpm dev` and `pnpm build` fail without it. +# Ask the docs team for the value; in CI it is provided by the repository variable of the same name. +# Note: VITE_ variables are compiled into the public browser bundle — never put secrets here. +VITE_CHANGELOG_ENDPOINT=https:///query diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index 826f4e5..6423b3d 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -44,6 +44,8 @@ jobs: - name: Build with VitePress run: pnpm run build + env: + VITE_CHANGELOG_ENDPOINT: ${{ vars.VITE_CHANGELOG_ENDPOINT }} - name: Upload artifact uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0 diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 95f1453..dc8d295 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -52,6 +52,8 @@ jobs: - name: Build run: pnpm build + env: + VITE_CHANGELOG_ENDPOINT: ${{ vars.VITE_CHANGELOG_ENDPOINT }} typo-check: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 61dffdf..6e1bfe2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ node_modules/ # Environment .env .env.* +!.env.example # IDE .vscode/ diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 2bfa680..66bf9b8 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -1,14 +1,24 @@ -import { defineConfig } from "vitepress"; +import { defineConfig, loadEnv } from "vitepress"; import { withMermaid } from "vitepress-plugin-mermaid"; import path from "node:path"; import { generateNav } from "./config/nav.js"; import { generateAllSidebars } from "./config/sidebar.js"; import { configureMarkdown } from "./config/markdown.js"; import { generateSitemap } from "./config/sitemap.js"; +import { + CHANGELOG_ENDPOINT_VAR, + CHANGELOG_PROXY_PATH, + resolveChangelogEndpoint, +} from "./config/changelog.js"; import llmstxt from "vitepress-plugin-llms"; const docsDir = path.join(process.cwd(), "docs"); +// Resolved at config load so a missing/invalid endpoint fails `pnpm dev` and +// `pnpm build` immediately, rather than shipping a page that errors at runtime. +const env = loadEnv("", process.cwd()); +const changelogEndpoint = resolveChangelogEndpoint(env[CHANGELOG_ENDPOINT_VAR]); + export default withMermaid( defineConfig({ title: "Tailor", @@ -38,6 +48,19 @@ export default withMermaid( optimizeDeps: { include: ["mermaid"], }, + // The changelog API does not allow cross-origin requests from localhost, so in + // `pnpm dev` the browser calls this same-origin path and Vite forwards it upstream. + // Production calls the API directly (see composables/useChangelogData.ts). + // Endpoint comes from VITE_CHANGELOG_ENDPOINT (see config/changelog.ts). + server: { + proxy: { + [CHANGELOG_PROXY_PATH]: { + target: changelogEndpoint.origin, + changeOrigin: true, + rewrite: (p) => p.replace(CHANGELOG_PROXY_PATH, ""), + }, + }, + }, plugins: [ llmstxt({ domain: "https://docs.tailor.tech", diff --git a/.vitepress/config/changelog.ts b/.vitepress/config/changelog.ts new file mode 100644 index 0000000..4783af0 --- /dev/null +++ b/.vitepress/config/changelog.ts @@ -0,0 +1,26 @@ +/** + * Changelog API endpoint configuration, shared by the Vite dev proxy (config.mts) + * and the client fetcher (theme/composables/useChangelogData.ts). + * + * The endpoint is intentionally not defaulted in source. It must be supplied via + * `VITE_CHANGELOG_ENDPOINT` (a full URL including the GraphQL path) — locally in + * `.env` (see .env.example), in CI via the repository variable of the same name. + */ +export const CHANGELOG_ENDPOINT_VAR = "VITE_CHANGELOG_ENDPOINT"; + +/** Same-origin path the dev server proxies to the upstream endpoint's origin. */ +export const CHANGELOG_PROXY_PATH = "/__changelog-api"; + +export function resolveChangelogEndpoint(raw: string | undefined): URL { + const value = raw?.trim(); + if (!value) { + throw new Error( + `${CHANGELOG_ENDPOINT_VAR} is not set. Add it to .env (see .env.example) or the CI environment.`, + ); + } + try { + return new URL(value); + } catch { + throw new Error(`${CHANGELOG_ENDPOINT_VAR} must be a full URL, got: ${value}`); + } +} diff --git a/.vitepress/theme/components/Changelog.vue b/.vitepress/theme/components/Changelog.vue index 030adfe..93c58ac 100644 --- a/.vitepress/theme/components/Changelog.vue +++ b/.vitepress/theme/components/Changelog.vue @@ -45,22 +45,41 @@

{{ entry.title }}

-
- What's new: {{ entry.narrative.summary }} -
-
- Impact: {{ entry.narrative.impact }} -
-
- Key changes: +
+

What's new

+

+

+
+

Impact

+

+

+
+

Key changes

    -
  • {{ detail }}
  • +
-
-
- ⚠️ Migration required: -
-
+ +
+

⚠️ Migration required

+ +
@@ -96,7 +115,13 @@