feat(site): link to the Console pages in the page's language (#66852)

This commit is contained in:
Jack 2026-11-28 04:24:45 +08:00 • committed by GitHub
parent 497569c6f2
commit 68ea328db1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 202 additions and 47 deletions

View file

@ -155,13 +155,13 @@ export function Header(props: { zen?: boolean; go?: boolean; hideGetStarted?: bo
<a href={language.route("/data")}>{i18n.t("nav.data")}</a>
</li>
<li>
<A href="/console/models">{i18n.t("nav.zen")}</A>
<A href={language.consoleRoute("/console/models")}>{i18n.t("nav.zen")}</A>
</li>
<li>
<A href="/console/go">{i18n.t("nav.go")}</A>
<A href={language.consoleRoute("/console/go")}>{i18n.t("nav.go")}</A>
</li>
<li>
<A href="/console/enterprise">{i18n.t("nav.enterprise")}</A>
<A href={language.consoleRoute("/console/enterprise")}>{i18n.t("nav.enterprise")}</A>
</li>
<Show when={props.zen || props.go}>
<li>
@ -256,16 +256,16 @@ export function Header(props: { zen?: boolean; go?: boolean; hideGetStarted?: bo
</li>
<Show when={!props.zen}>
<li>
<A href="/console/models">{i18n.t("nav.zen")}</A>
<A href={language.consoleRoute("/console/models")}>{i18n.t("nav.zen")}</A>
</li>
</Show>
<Show when={!props.go}>
<li>
<A href="/console/go">{i18n.t("nav.go")}</A>
<A href={language.consoleRoute("/console/go")}>{i18n.t("nav.go")}</A>
</li>
</Show>
<li>
<A href="/console/enterprise">{i18n.t("nav.enterprise")}</A>
<A href={language.consoleRoute("/console/enterprise")}>{i18n.t("nav.enterprise")}</A>
</li>
<Show when={props.zen || props.go}>
<li>

View file

@ -49,7 +49,7 @@ export { arcadeMenu }
export function ArcadeChrome(props: { settingsRows?: () => JSX.Element }) {
const i18n = useI18n()
const language = useLanguage()
const links = createMemo(() => siteLinks(i18n.t, language.route))
const links = createMemo(() => siteLinks(i18n.t, language.route, language.consoleRoute))
useViewportCover()
// The same items and order as the site's sidebar (site.tsx) with the current settings.
const nav = createMemo(() => {

View file

@ -1,6 +1,7 @@
import "./byos-options.css"
import { For, Show } from "solid-js"
import { useI18n } from "~/context/i18n"
import { useLanguage } from "~/context/language"
import { rich } from "~/i18n/rich"
import { byos } from "~/lib/byos"
import { byosOptions } from "~/lib/byos-options"
@ -24,11 +25,12 @@ const providers = marks.filter((provider) => !shown.has(provider.id))
/** Each option's lead, in place of the section's own (inside its lead paragraph). */
export function ByosOptionLeads() {
const language = useLanguage()
const link = (text: string) => (
<Rich
value={linkPhrases(
text,
byos.planLinks.map((phrase) => ({ text: phrase, href: byos.plansHref })),
byos.planLinks.map((phrase) => ({ text: phrase, href: language.consoleRoute(byos.plansHref) })),
)}
/>
)
@ -43,6 +45,7 @@ export function ByosOptionLeads() {
export function ByosOptions() {
const i18n = useI18n()
const language = useLanguage()
const providersLink = docsUrl("/providers/")
return (
<div data-slot="options">
@ -100,7 +103,7 @@ export function ByosOptions() {
<For each={byosOptions.opencode}>
{(item) => (
<li>
<a href={item.href}>{item.name}</a>
<a href={language.consoleRoute(item.href)}>{item.name}</a>
</li>
)}
</For>

View file

@ -4,7 +4,7 @@ import { docsUrl } from "~/lib/docs"
import type { Translate } from "~/i18n"
/** The sidebar and footer links, shared by the layout and the Markdown versions of the pages. */
export function siteLinks(t: Translate, route: (path: string) => string) {
export function siteLinks(t: Translate, route: (path: string) => string, consoleHref = route) {
return {
// Every item the primary nav can show, in the default order (settings.ts navDefaults says which
// show by default). Design mode reorders, hides and renames them (settings navConfig); the links
@ -22,14 +22,26 @@ export function siteLinks(t: Translate, route: (path: string) => string) {
{
id: "console",
label: t("site.nav.console"),
href: "/console",
href: consoleHref("/console"),
demo: route("/console-demo"),
arrow: true,
company: true,
},
{ id: "models", label: t("site.nav.models"), href: "/console/models", arrow: true, company: true },
{ id: "subscriptions", label: t("site.nav.subscriptions"), href: "/console/go", arrow: true, company: true },
{ id: "enterprise", label: t("nav.enterprise"), href: "/console/enterprise", arrow: true, company: true },
{ id: "models", label: t("site.nav.models"), href: consoleHref("/console/models"), arrow: true, company: true },
{
id: "subscriptions",
label: t("site.nav.subscriptions"),
href: consoleHref("/console/go"),
arrow: true,
company: true,
},
{
id: "enterprise",
label: t("nav.enterprise"),
href: consoleHref("/console/enterprise"),
arrow: true,
company: true,
},
{ id: "changelog", label: t("footer.changelog"), href: route("/changelog") },
// Also the GitHub mark in the top-right corner (site.tsx).
{ id: "github", label: t("nav.github"), href: config.github.repoUrl, external: true, arrow: true },
@ -86,10 +98,10 @@ export function siteLinks(t: Translate, route: (path: string) => string) {
{
title: "Anomaly",
links: [
{ label: t("site.nav.console"), href: "/console" },
{ label: "OpenCode Models", href: "/console/models" },
{ label: t("site.nav.subscriptions"), href: "/console/go" },
{ label: t("nav.enterprise"), href: "/console/enterprise" },
{ label: t("site.nav.console"), href: consoleHref("/console") },
{ label: "OpenCode Models", href: consoleHref("/console/models") },
{ label: t("site.nav.subscriptions"), href: consoleHref("/console/go") },
{ label: t("nav.enterprise"), href: consoleHref("/console/enterprise") },
{ label: t("legal.privacy"), href: route("/legal/privacy-policy") },
{ label: t("legal.terms"), href: route("/legal/terms-of-service") },
],

View file

@ -5,7 +5,7 @@ import { localize } from "~/i18n/content"
import { extensionsSource } from "~/i18n/content/areas/extensions"
import { productDetailsSource } from "~/i18n/content/areas/product-details"
import { productsSource } from "~/i18n/content/areas/products"
import type { Locale } from "~/lib/language"
import { consoleRoute, type Locale } from "~/lib/language"
import { brandContent, brandMarkdown } from "~/lib/brand-content"
import { brandAssets } from "~/lib/media"
import type { ChangelogRelease } from "~/lib/changelog"
@ -60,7 +60,7 @@ export function buildSearchIndex(
locale: Locale,
dev: boolean,
): SearchItem[] {
const home = homeContent(t, route)
const home = homeContent(t, route, (path) => consoleRoute(locale, path))
const download = localize(locale, "download", downloadContent(t, route))
const press = localize(locale, "press", pressContent(t, route))
const brand = localize(locale, "brand", brandContent(t))
@ -132,9 +132,17 @@ export function buildSearchIndex(
}),
)
const external: SearchItem[] = [
{ title: t("site.nav.console"), href: "/console", keywords: "models subscriptions zen go" },
{ title: t("site.nav.subscriptions"), href: "/console/go", keywords: "go go plus plans pricing subscribe" },
{ title: t("nav.enterprise"), href: "/console/enterprise", keywords: "sales business teams" },
{ title: t("site.nav.console"), href: consoleRoute(locale, "/console"), keywords: "models subscriptions zen go" },
{
title: t("site.nav.subscriptions"),
href: consoleRoute(locale, "/console/go"),
keywords: "go go plus plans pricing subscribe",
},
{
title: t("nav.enterprise"),
href: consoleRoute(locale, "/console/enterprise"),
keywords: "sales business teams",
},
{ title: "GitHub", href: config.github.repoUrl, keywords: "source repo code" },
].map((page) => ({ id: `page:${page.href}`, group: "Pages", context: page.href, ...page }))
@ -311,7 +319,7 @@ export function buildSearchIndex(
/** The brand page as Markdown, as its "Copy rules for your agent" button copies it. */
export function brandRules(t: Translate, route: (path: string) => string) {
return markdownDocument("/brand", brandMarkdown, { t, route })
return markdownDocument("/brand", brandMarkdown, { t, route, consoleRoute: route })
}
/** Changelog entries and their versions, from the same JSON the changelog serves. */

View file

@ -395,7 +395,7 @@ export function Site(props: {
}
// Follows the locale, so a client-side language switch relabels the nav and footer.
const links = createMemo(() => siteLinks(i18n.t, language.route))
const links = createMemo(() => siteLinks(i18n.t, language.route, language.consoleRoute))
// Every known item renders, in the saved list's order (Design mode shows the hidden ones, dimmed);
// the shown ones are numbered and take the number keys. The items stay the same objects while the
// list changes, so a reorder moves them in place.

View file

@ -54,6 +54,7 @@ function useMarkdownContext(data: MarkdownData) {
return (): MarkdownContext => ({
t: i18n.t,
route: language.route,
consoleRoute: language.consoleRoute,
changelog: data.changelog?.(),
releases: data.releases?.(),
})

View file

@ -15,6 +15,7 @@ import {
localized,
pageLocale,
parseLocale,
consoleRoute as localeConsoleRoute,
route as localeRoute,
tag as localeTag,
} from "~/lib/language"
@ -81,6 +82,9 @@ export const { use: useLanguage, provider: LanguageProvider } = createSimpleCont
route(pathname: string) {
return localeRoute(current(), pathname)
},
consoleRoute(pathname: string) {
return localeConsoleRoute(current(), pathname)
},
setLocale(next: Locale) {
setCurrent(next)
if (typeof document !== "object") return

View file

@ -17,13 +17,13 @@ import { docsUrl } from "~/lib/docs"
/** The free models the site names (models.dev's opencode provider has the full, live list). */
export const freeModels = ["Big Pickle", "DeepSeek V4.1 Flash Free"]
export function getStarted(route: (path: string) => string) {
export function getStarted(route: (path: string) => string, consoleHref = route) {
const links = {
download: route("/product"),
// The docs' list of the free models (its pricing table above mixes in the paid ones).
free: route(docsUrl("/console/models/#free-models")),
subs: route(docsUrl("/providers/")),
go: "/console/go",
go: consoleHref("/console/go"),
}
return {
title: "Get started",
@ -40,8 +40,8 @@ export function getStarted(route: (path: string) => string) {
freeModels,
subscriptions: byos.yours.items,
plans: [
{ name: "OpenCode Go", amount: "$10", href: "/console/go#console-go-plan-go" },
{ name: "OpenCode Go Plus", amount: "$40", href: "/console/go#console-go-plan-go-plus" },
{ name: "OpenCode Go", amount: "$10", href: consoleHref("/console/go#console-go-plan-go") },
{ name: "OpenCode Go Plus", amount: "$40", href: consoleHref("/console/go#console-go-plan-go-plus") },
],
steps: [
{ title: "Download", line: "Desktop, terminal or mobile." },

View file

@ -31,7 +31,7 @@ export function linkPhrases(text: string, links: readonly { text: string; href:
* The home page copy, shared by the page and its Markdown version so the two never drift.
* `route` localizes a site path.
*/
export function homeContent(t: Translate, route: (path: string) => string) {
export function homeContent(t: Translate, route: (path: string) => string, consoleHref = route) {
const docs = (path: string) => `https://opencode.ai${docsUrl(path)}`
return {
title: t("home.title"),
@ -163,10 +163,10 @@ export function homeContent(t: Translate, route: (path: string) => string) {
title: t("site.nav.console"),
headline: t("home.console.headline"),
body: t("home.console.body"),
cta: { text: t("home.console.cta"), href: "/console" },
cta: { text: t("home.console.cta"), href: consoleHref("/console") },
// The slim option: one line that names the Console, and a second action.
slimHeadline: t("home.console.slimHeadline"),
sales: { text: t("home.console.sales"), href: "/console/enterprise" },
sales: { text: t("home.console.sales"), href: consoleHref("/console/enterprise") },
},
}
}

View file

@ -9,9 +9,9 @@ import { productActionMarkdown } from "~/lib/product-markdown"
/** The home page as Markdown, for `/index.md` and the in-page Markdown view. */
export function homeMarkdown(context: MarkdownContext) {
const content = homeContent(context.t, context.route)
const links = siteLinks(context.t, context.route)
const start = getStarted(context.route)
const content = homeContent(context.t, context.route, context.consoleRoute)
const links = siteLinks(context.t, context.route, context.consoleRoute)
const start = getStarted(context.route, context.consoleRoute)
return blocks(
`# ${content.hero.title}`,
@ -35,7 +35,7 @@ export function homeMarkdown(context: MarkdownContext) {
`${byos.headline} ${richToMarkdown(
linkPhrases(
byos.line,
byos.planLinks.map((text) => ({ text, href: byos.plansHref })),
byos.planLinks.map((text) => ({ text, href: context.consoleRoute(byos.plansHref) })),
),
)}`,
`## ${content.tools.title}`,

View file

@ -135,6 +135,35 @@ export function label(locale: Locale) {
return LABEL[locale]
}
// The Console serves its marketing pages at /<locale>/console/... and keeps the guides and app
// pages (workspace, login, ...) at /console/...; consoleRoute leaves those alone too.
const consoleMarketing = [
"/console",
"/console/models",
"/console/go",
"/console/enterprise",
"/console/teams",
"/console/support",
"/console/integrations",
]
/** True for one of the Console's marketing pages, and only that page: its guides stay English. */
function consoleMarketingPath(pathname: string) {
const path = pathname.split(/[?#]/, 1)[0]?.replace(/\/$/, "") || "/"
return consoleMarketing.includes(path)
}
/**
* A link to a Console marketing page in the page's language. The Console serves its marketing pages
* at /<locale>/console/... and keeps its guides and app pages (workspace, login, ...) at /console/...;
* this app's own route() leaves /console unprefixed (localized() excludes it).
*/
export function consoleRoute(locale: Locale, pathname: string) {
const next = strip(pathname)
if (locale === "en" || !consoleMarketingPath(next)) return next
return `/${locale}${next}`
}
export function english(locale: Locale) {
return ENGLISH[locale]
}

View file

@ -1,4 +1,4 @@
import type { Locale } from "~/lib/language"
import { consoleRoute, type Locale } from "~/lib/language"
import { desktopAssets, updateApi } from "~/lib/download"
// LEGACY REDIRECTS, every one to be removed later. Old URLs that outside links, bookmarks, scripts
@ -32,7 +32,7 @@ export function legacyRedirect(request: Legacy): Response | undefined {
// links (`/go` about 75k requests a day, `/zen` 46k). Exact paths only: /zen/v1/* and /zen/go/v1/*
// are the inference API, which a prefix match here would break.
const moved = (request.locale ? localizedMoves : moves).get(request.path.replace(/(.)\/$/, "$1"))
if (moved && read) return redirect(301, `${moved}${request.search}`)
if (moved && read) return redirect(301, `${request.locale ? consoleRoute(request.locale, moved) : moved}${request.search}`)
// The legacy dashboard and its sign-in, now the Console. The V1 CLI's "create a key at /auth" and
// V1's usage-limit link /workspace/<id>/go (about 50k requests a day).
@ -83,7 +83,8 @@ const moves = new Map([
["/enterprise", "/console/enterprise"],
])
// The old site rendered these three pages in every language; their localized URLs follow them.
// The old site rendered these three pages in every language; their localized URLs follow them, and a
// non-English URL keeps its language in the Console page it redirects to.
const localizedMoves = new Map([
["/go", "/console/go"],
["/zen", "/console/models"],

View file

@ -11,7 +11,7 @@ import { markdownContext, pageMarkdown } from "~/lib/page-markdown"
/** The llms.txt index (https://llmstxt.org): what OpenCode is and the Markdown version of every page. */
export async function llmsText(locale: Locale) {
const context = await markdownContext(locale)
const content = homeContent(context.t, context.route)
const content = homeContent(context.t, context.route, context.consoleRoute)
const page = (path: string) =>
`- ${link(pageMarkdown[path].title, context.route(markdownPath(path)))}: ${pageMarkdown[path].description}`
const docs = (title: string, path: string, description: string) => `- ${link(title, docsUrl(path))}: ${description}`

View file

@ -11,6 +11,7 @@ export type RichText = Inline[]
export type MarkdownContext = {
t: Translate
route: (path: string) => string
consoleRoute: (path: string) => string
changelog?: ChangelogView
/** The releases as they come from GitHub, for pages that read them directly (the press kit). */
releases?: ChangelogRelease[]

View file

@ -6,7 +6,7 @@ import { changelogEntryPageMarkdown, changelogMarkdown } from "~/lib/changelog-m
import { areaKeys, changelogEntryView, changelogView, type ChangelogView } from "~/lib/changelog-notes"
import { fontMarkdown } from "~/lib/font-content"
import { homeMarkdown } from "~/lib/home-markdown"
import { route, type Locale } from "~/lib/language"
import { consoleRoute, route, type Locale } from "~/lib/language"
import { legalMarkdown } from "~/lib/legal"
import { legalHubMarkdown } from "~/lib/legal-documents"
import { privacyPolicy } from "~/lib/legal/privacy-policy"
@ -136,6 +136,7 @@ export async function markdownContext(
return {
t: translator(locale),
route: (path) => route(locale, path),
consoleRoute: (path) => consoleRoute(locale, path),
changelog: page?.changelog?.(releases, query),
releases: page?.releases ? releases : undefined,
}

View file

@ -13,7 +13,9 @@ export const sitemapFiles = [
"/sitemap-pages.xml", // this app's pages, built below
"/docs/sitemap.xml", // the V2 docs (src/docs)
"/data/sitemap.xml", // the Data pages, from the stats app
"/console/sitemap.xml", // the Console pages, from the Console app
"/console/sitemap.xml", // the Console pages, from the Console app, in English
// The same pages from the Console app in the site's other languages.
...LOCALES.filter((locale) => locale !== "en").map((locale) => `/${locale}/console/sitemap.xml`),
]
/** The sitemaps as a sitemaps.org `sitemapindex`. */

View file

@ -96,7 +96,7 @@ export default function Home() {
siteSettings.consoleLayout === "block" && siteSettings.consoleSection !== "off"
? "panel"
: siteSettings.consoleSection
const content = createMemo(() => homeContent(i18n.t, language.route))
const content = createMemo(() => homeContent(i18n.t, language.route, language.consoleRoute))
// Its own meta description (140–155 characters). Until a locale translates it, the locale keeps
// the tagline and hero subtitle it already has in its language.
const description = () =>
@ -956,7 +956,9 @@ function stripTags(html: string) {
function GetStarted() {
const i18n = useI18n()
const language = useLanguage()
const content = createMemo(() => localize(language.locale(), "getStarted", getStarted(language.route)))
const content = createMemo(() =>
localize(language.locale(), "getStarted", getStarted(language.route, language.consoleRoute)),
)
// On a phone or tablet, Download is that device's app; on a computer, the desktop build.
const platform = useDevicePlatform()
const downloadSlug = () => (isMobile(platform()) ? "mobile" : "desktop")
@ -1189,7 +1191,7 @@ function BringYourOwnSubs() {
const [tab, setTab] = createSignal<"yours" | "ours">("yours")
const yours = () => <ToolGrid items={subs().yours.items} label={subs().yours.label} iconTiles />
const providers = () => <ToolGrid items={subs().providers} label={i18n.t("home.byos.providersLabel")} iconTiles />
const goHref = () => subs().plansHref
const goHref = () => language.consoleRoute(subs().plansHref)
const select = (next: "yours" | "ours", focus?: boolean) => {
setTab(next)
if (focus) document.getElementById(`byos-tab-${next}`)?.focus()

View file

@ -0,0 +1,82 @@
import { describe, expect, test } from "bun:test"
import { siteLinks } from "~/component/site/links"
import { translator } from "~/i18n"
import { getStarted } from "~/lib/get-started"
import { homeContent } from "~/lib/home-content"
import { consoleRoute, localized, route } from "~/lib/language"
const t = translator("en")
const de = (path: string) => consoleRoute("de", path)
describe("consoleRoute", () => {
test("prefixes the Console's marketing pages for non-English pages", () => {
for (const path of [
"/console",
"/console/models",
"/console/go",
"/console/enterprise",
"/console/teams",
"/console/support",
"/console/integrations",
])
expect(consoleRoute("de", path)).toBe(`/de${path}`)
expect(consoleRoute("ru", "/console/go#console-go-plan-go")).toBe("/ru/console/go#console-go-plan-go")
expect(consoleRoute("de", "/de/console/models/")).toBe("/de/console/models/")
expect(consoleRoute("de", "/console/models?sort=price")).toBe("/de/console/models?sort=price")
})
test("leaves English and the Console's app pages alone", () => {
expect(consoleRoute("en", "/console/go")).toBe("/console/go")
for (const path of [
"/console/workspace",
"/console/login",
"/console/funnel/v1.js",
"/console/sitemap.xml",
"/auth",
])
expect(consoleRoute("de", path)).toBe(path)
})
test("matches marketing pages exactly, not their subpaths", () => {
expect(consoleRoute("de", "/console/models/compare")).toBe("/console/models/compare")
expect(consoleRoute("de", "/console/integrations/slack")).toBe("/console/integrations/slack")
})
test("keeps the middleware redirect for prefixed Console URLs", () => {
// localized() excludes /console, so /de/console 301s to /console until the Console serves it.
expect(localized("/console")).toBe(false)
expect(localized("/console/go")).toBe(false)
expect(route("de", "/de/console")).toBe("/console")
})
})
describe("localized Console links", () => {
test("the sidebar and footer use the page's language for Console marketing pages", () => {
const links = siteLinks(t, (path) => route("de", path), de)
const nav = Object.fromEntries(links.nav.map((item) => [item.id, item.href]))
expect(nav.console).toBe("/de/console")
expect(nav.models).toBe("/de/console/models")
expect(nav.subscriptions).toBe("/de/console/go")
expect(nav.enterprise).toBe("/de/console/enterprise")
expect(nav.docs).toBe("/docs")
const anomaly = links.columns.find((column) => column.title === "Anomaly")
expect(anomaly?.links.filter((item) => item.href.startsWith("/de/console")).map((item) => item.href)).toEqual([
"/de/console",
"/de/console/models",
"/de/console/go",
"/de/console/enterprise",
])
})
test("the home Console and Get started CTAs follow the page's language", () => {
const content = homeContent(t, (path) => route("de", path), de)
expect(content.console.cta.href).toBe("/de/console")
expect(content.console.sales.href).toBe("/de/console/enterprise")
const start = getStarted((path) => route("de", path), de)
expect(start.links.go).toBe("/de/console/go")
expect(start.plans.map((plan) => plan.href)).toEqual([
"/de/console/go#console-go-plan-go",
"/de/console/go#console-go-plan-go-plus",
])
})
})

View file

@ -40,8 +40,13 @@ describe("legacy redirects", () => {
expect(get("/go", { method: "POST" })).toBeUndefined()
})
test("localized go, zen and enterprise follow to the Console; other localized moves don't", () => {
expect(get("/enterprise", { locale: "de" })?.headers.get("Location")).toBe("/console/enterprise")
test("localized go, zen and enterprise follow to the Console in their language; other localized moves don't", () => {
expect(get("/go", { locale: "de" })?.headers.get("Location")).toBe("/de/console/go")
expect(get("/zen", { locale: "de" })?.headers.get("Location")).toBe("/de/console/models")
expect(get("/zen", { locale: "de", search: "?ref=app" })?.headers.get("Location")).toBe(
"/de/console/models?ref=app",
)
expect(get("/enterprise", { locale: "de" })?.headers.get("Location")).toBe("/de/console/enterprise")
expect(get("/pricing", { locale: "de" })).toBeUndefined()
})

View file

@ -53,6 +53,10 @@ describe("sitemap", () => {
expect(files).toEqual(sitemapFiles.map((file) => `${config.baseUrl}${file}`))
expect(files).toContain(`${config.baseUrl}/sitemap-pages.xml`)
expect(files).toContain(`${config.baseUrl}/docs/sitemap.xml`)
expect(files).toContain(`${config.baseUrl}/console/sitemap.xml`)
for (const locale of LOCALES.filter((locale) => locale !== "en"))
expect(files).toContain(`${config.baseUrl}/${locale}/console/sitemap.xml`)
expect(files).not.toContain(`${config.baseUrl}/en/console/sitemap.xml`)
expect(files.some((file) => file === `${config.baseUrl}/sitemap.xml`)).toBe(false)
})