diff --git a/services/site/cloudflare.config.ts b/services/site/cloudflare.config.ts index 515ce62e952..7b68643f0b0 100644 --- a/services/site/cloudflare.config.ts +++ b/services/site/cloudflare.config.ts @@ -45,7 +45,7 @@ export default defineConfig(({ mode }) => { : [], // The bare host is a custom domain (it also supplies the DNS record), and cf detaches any domain // not listed here. docs. is the old docs host: the Worker sends its URLs to the same path - // on the V1 docs at /v1/docs. + // under /docs. domains: [host, `docs.${host}`], workersDev: false, previewUrls: false, diff --git a/services/site/src/docs/AGENTS.md b/services/site/src/docs/AGENTS.md index 1ac29d3801e..2f4c96d6861 100644 --- a/services/site/src/docs/AGENTS.md +++ b/services/site/src/docs/AGENTS.md @@ -27,7 +27,7 @@ - `script/build.ts` runs after the site's `vite build` (from `script/build.ts` at the site root): it builds the docs' stylesheet and script, prerenders every page, every content page's Markdown twin (`/docs/config.md`; the intro's is `/docs/index.md`), `llms.txt` and the sitemap into `.output/public`, builds the Pagefind index, and checks every link, that nothing loads from outside `/docs` and that no page takes a reserved file name. `llms.txt` and the sitemap list opencode.ai's URLs on dev.opencode.ai too, so dev never advertises its own. - Pull requests that touch the site run the same build on its own (`.github/workflows/check-docs.yml`): `bun run generate`, then `bun src/docs/script/build.ts --out `. - The Worker never renders docs. `middleware.ts` serves the prerendered files: docs URLs reach it first (`runWorkerFirst` in `cloudflare.config.ts`), so a page's URL answers `Accept: text/markdown` with its twin. `vite dev` has no prerendered files, so the development server renders on request. -- `/docs` still receives the V1 docs' old links, which had more pages and other languages (`/docs/ja/...`). `middleware.ts` redirects any `/docs` path that isn't a page here (`virtual:docs-pages`, the same list the build prerenders) to the same path on the V1 docs with a 302, so adding a page here takes its URL over. `route.ts` also answers the V1 app's other addresses (its language aliases, share links and schemas) and, ahead of docs.opencode.ai moving to this Worker, sends that host's paths to `/v1/docs`. The old `/v2` URLs redirect to `/docs` permanently (`src/lib/legacy.ts`). +- `/docs` still receives the V1 docs' old links, which had more pages and other languages (`/docs/ja/...`). `middleware.ts` redirects any `/docs` path that isn't a page here (`virtual:docs-pages`, the same list the build prerenders) to the same path on the V1 docs with a 302, so adding a page here takes its URL over. `route.ts` also answers the V1 app's other addresses (its language aliases, share links and schemas) and, ahead of docs.opencode.ai moving to this Worker, sends that host's paths to the same path under `/docs`. The old `/v2` URLs redirect to `/docs` permanently (`src/lib/legacy.ts`). ## Writing Style diff --git a/services/site/src/docs/route.ts b/services/site/src/docs/route.ts index 7f7cb1fa5ca..3900aac3674 100644 --- a/services/site/src/docs/route.ts +++ b/services/site/src/docs/route.ts @@ -34,19 +34,30 @@ export function docsRoute(url: URL, accept: string, slugs: Record/go (about 50k requests a day). diff --git a/services/site/test/docs-route.test.ts b/services/site/test/docs-route.test.ts index 560bea2c882..d731fe3ff37 100644 --- a/services/site/test/docs-route.test.ts +++ b/services/site/test/docs-route.test.ts @@ -67,7 +67,7 @@ describe("docs routes", () => { }) test("send paths without a V2 page to the same path on the V1 docs, temporarily", () => { - for (const path of ["/docs/ja/", "/docs/ja/agents/", "/docs/zh-cn/config", "/docs/ide/", "/docs/sdk.md"]) + for (const path of ["/docs/ja/", "/docs/ja/agents/", "/docs/zh-cn/config", "/docs/ide/", "/docs/lsp.md"]) expect(route(path)).toEqual({ type: "redirect", location: `/v1/docs${path.slice("/docs".length)}`, status: 302 }) expect(route("/docs/ide/?ref=app")).toEqual({ type: "redirect", location: "/v1/docs/ide/?ref=app", status: 302 }) }) @@ -80,6 +80,9 @@ describe("docs routes", () => { }) expect(route("/docs/go")).toEqual({ type: "redirect", location: "/docs/console/go/", status: 301 }) expect(route("/docs/zen/")).toEqual({ type: "redirect", location: "/docs/console/models/", status: 301 }) + expect(route("/docs/rules/")).toEqual({ type: "redirect", location: "/docs/instructions/", status: 301 }) + expect(route("/docs/sdk")).toEqual({ type: "redirect", location: "/docs/build/sdk/", status: 301 }) + expect(route("/docs/server/")).toEqual({ type: "redirect", location: "/docs/api", status: 301 }) }) test("leave the docs' own files to the assets, never to the V1 docs", () => { @@ -131,13 +134,13 @@ describe("V1 docs routes", () => { expect(route(path)).toEqual({ type: "missing" }) }) - test("send docs.opencode.ai's addresses to the same path on the V1 docs", () => { + test("send docs.opencode.ai's addresses to the same path under /docs", () => { const host = (url: string) => docsHostRedirect(new URL(url)) - expect(host("https://docs.opencode.ai/")).toBe("https://opencode.ai/v1/docs/") - expect(host("https://docs.opencode.ai/docs")).toBe("https://opencode.ai/v1/docs/") - expect(host("https://docs.opencode.ai/docs/ide/?x=1")).toBe("https://opencode.ai/v1/docs/ide/?x=1") - expect(host("https://docs.opencode.ai/s/abc")).toBe("https://opencode.ai/v1/docs/s/abc") - expect(host("https://docs.dev.opencode.ai/docs/ja/")).toBe("https://dev.opencode.ai/v1/docs/ja/") + expect(host("https://docs.opencode.ai/")).toBe("https://opencode.ai/docs/") + expect(host("https://docs.opencode.ai/docs")).toBe("https://opencode.ai/docs/") + expect(host("https://docs.opencode.ai/docs/ide/?x=1")).toBe("https://opencode.ai/docs/ide/?x=1") + expect(host("https://docs.opencode.ai/s/abc")).toBe("https://opencode.ai/docs/s/abc") + expect(host("https://docs.dev.opencode.ai/docs/ja/")).toBe("https://dev.opencode.ai/docs/ja/") expect(host("https://opencode.ai/docs/")).toBeUndefined() }) }) diff --git a/services/site/test/legacy.test.ts b/services/site/test/legacy.test.ts index 78e6287872c..6a48905ea0c 100644 --- a/services/site/test/legacy.test.ts +++ b/services/site/test/legacy.test.ts @@ -31,9 +31,8 @@ describe("legacy redirects", () => { test("moved pages match exact paths only, keep the query and leave the inference API alone", () => { const zen = get("/zen/", { search: "?ref=app" }) - expect(zen?.status).toBe(302) + expect(zen?.status).toBe(301) expect(zen?.headers.get("Location")).toBe("/console/models?ref=app") - expect(zen?.headers.get("Cache-Control")).toBe("no-store") expect(get("/zen/go")?.headers.get("Location")).toBe("/console/go") expect(get("/teams")?.headers.get("Location")).toBe("/console/teams") for (const path of ["/zen/v1/models", "/zen/go/v1/chat/completions", "/go/v1", "/models.json", "/gopher"])