From 05c22a33242b4b1973d942e38a22a541b9e8edab Mon Sep 17 00:00:00 2001 From: Aolin Date: Fri, 21 Nov 2025 17:06:41 +0800 Subject: [PATCH 1/3] feat: return "dev" for Operator main branch --- gatsby/path.ts | 1 + gatsby/utils.ts | 1 + src/shared/utils/index.ts | 2 ++ 3 files changed, 4 insertions(+) diff --git a/gatsby/path.ts b/gatsby/path.ts index 384c22542..8f380580b 100644 --- a/gatsby/path.ts +++ b/gatsby/path.ts @@ -90,6 +90,7 @@ function branchToVersion(repo: Repo, branch: string) { const stable = CONFIG.docs[repo].stable; switch (branch) { case "master": + case "main": return "dev"; case stable: return "stable"; diff --git a/gatsby/utils.ts b/gatsby/utils.ts index 8c52ae624..be5e7f496 100644 --- a/gatsby/utils.ts +++ b/gatsby/utils.ts @@ -24,6 +24,7 @@ export function getStable(doc: Repo) { function renameVersion(version: string, stable: string | undefined) { switch (version) { case "master": + case "main": return "dev"; case stable: return "stable"; diff --git a/src/shared/utils/index.ts b/src/shared/utils/index.ts index 72beeee6c..45f4ef515 100644 --- a/src/shared/utils/index.ts +++ b/src/shared/utils/index.ts @@ -187,6 +187,7 @@ function branchToVersion(repo: Repo, branch: string) { const stable = CONFIG.docs[repo].stable; switch (branch) { case "master": + case "main": return "dev"; case stable: return "stable"; @@ -217,6 +218,7 @@ export const AllVersion = Object.keys(CONFIG.docs).reduce((acc, val) => { export function convertVersionName(version: string, stable: string) { switch (version) { case "master": + case "main": return "dev"; case stable: return "stable"; From 05bb57fab39f0d7c0dcc0ac82bd114a19a59838c Mon Sep 17 00:00:00 2001 From: Aolin Date: Fri, 21 Nov 2025 17:33:26 +0800 Subject: [PATCH 2/3] feat: return "dev" for Operator main branch --- gatsby/path.ts | 13 +++++++++++-- src/shared/utils/index.ts | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/gatsby/path.ts b/gatsby/path.ts index 8f380580b..b59567ec9 100644 --- a/gatsby/path.ts +++ b/gatsby/path.ts @@ -85,11 +85,20 @@ export function generateConfig(slug: string): { function branchToVersion(repo: Repo, branch: string) { switch (repo) { - case Repo.tidb: - case Repo.operator: { + case Repo.tidb: { const stable = CONFIG.docs[repo].stable; switch (branch) { case "master": + return "dev"; + case stable: + return "stable"; + default: + return branch.replace("release-", "v"); + } + } + case Repo.operator: { + const stable = CONFIG.docs[repo].stable; + switch (branch) { case "main": return "dev"; case stable: diff --git a/src/shared/utils/index.ts b/src/shared/utils/index.ts index 45f4ef515..10d0cf39b 100644 --- a/src/shared/utils/index.ts +++ b/src/shared/utils/index.ts @@ -182,11 +182,20 @@ export function getBannerByType(type: "home" | "tidb" | "tidb-cloud") { function branchToVersion(repo: Repo, branch: string) { switch (repo) { - case Repo.tidb: - case Repo.operator: { + case Repo.tidb: { const stable = CONFIG.docs[repo].stable; switch (branch) { case "master": + return "dev"; + case stable: + return "stable"; + default: + return branch.replace("release-", "v"); + } + } + case Repo.operator: { + const stable = CONFIG.docs[repo].stable; + switch (branch) { case "main": return "dev"; case stable: From 844dabaa6f094f0ea918a6fdfb92aeb925842021 Mon Sep 17 00:00:00 2001 From: Aolin Date: Fri, 21 Nov 2025 18:21:38 +0800 Subject: [PATCH 3/3] refactor --- gatsby/path.ts | 15 +++------------ gatsby/utils.ts | 26 ++++++++++++-------------- src/shared/resources.ts | 2 +- src/shared/utils/index.ts | 21 ++++++--------------- 4 files changed, 22 insertions(+), 42 deletions(-) diff --git a/gatsby/path.ts b/gatsby/path.ts index b59567ec9..4a28e0e22 100644 --- a/gatsby/path.ts +++ b/gatsby/path.ts @@ -85,21 +85,12 @@ export function generateConfig(slug: string): { function branchToVersion(repo: Repo, branch: string) { switch (repo) { - case Repo.tidb: { - const stable = CONFIG.docs[repo].stable; - switch (branch) { - case "master": - return "dev"; - case stable: - return "stable"; - default: - return branch.replace("release-", "v"); - } - } + case Repo.tidb: case Repo.operator: { + const devBranch = repo === Repo.operator ? "main" : "master"; const stable = CONFIG.docs[repo].stable; switch (branch) { - case "main": + case devBranch: return "dev"; case stable: return "stable"; diff --git a/gatsby/utils.ts b/gatsby/utils.ts index be5e7f496..fd9aed53e 100644 --- a/gatsby/utils.ts +++ b/gatsby/utils.ts @@ -21,24 +21,22 @@ export function getStable(doc: Repo) { return undefined; } -function renameVersion(version: string, stable: string | undefined) { - switch (version) { - case "master": - case "main": - return "dev"; - case stable: - return "stable"; - default: - return version.replace("release-", "v"); - } -} - export function renameVersionByDoc(doc: Repo, version: string) { switch (doc) { case "tidb": case "tidb-data-migration": - case "tidb-in-kubernetes": - return renameVersion(version, getStable(doc)); + case "tidb-in-kubernetes": { + const devBranch = doc === "tidb-in-kubernetes" ? "main" : "master"; + const stable = getStable(doc); + switch (version) { + case devBranch: + return "dev"; + case stable: + return "stable"; + default: + return version.replace("release-", "v"); + } + } case "tidbcloud": return; } diff --git a/src/shared/resources.ts b/src/shared/resources.ts index fcbf68ab5..9874331a4 100644 --- a/src/shared/resources.ts +++ b/src/shared/resources.ts @@ -497,7 +497,7 @@ export const TIDB_ZH_VERSIONS = CONFIG["docs"]["tidb"]["languages"]["zh"][ export const OP_EN_VERSIONS = CONFIG["docs"]["tidb-in-kubernetes"]["languages"][ "en" -]["versions"].map((d) => convertVersionName(d, OP_EN_STABLE_VERSION)); +]["versions"].map((d) => convertVersionName(d, OP_EN_STABLE_VERSION, "tidb-in-kubernetes")); export const CLOUD_EN_VERSIONS = []; diff --git a/src/shared/utils/index.ts b/src/shared/utils/index.ts index 10d0cf39b..0d3d1652b 100644 --- a/src/shared/utils/index.ts +++ b/src/shared/utils/index.ts @@ -182,21 +182,12 @@ export function getBannerByType(type: "home" | "tidb" | "tidb-cloud") { function branchToVersion(repo: Repo, branch: string) { switch (repo) { - case Repo.tidb: { - const stable = CONFIG.docs[repo].stable; - switch (branch) { - case "master": - return "dev"; - case stable: - return "stable"; - default: - return branch.replace("release-", "v"); - } - } + case Repo.tidb: case Repo.operator: { + const devBranch = repo === Repo.operator ? "main" : "master"; const stable = CONFIG.docs[repo].stable; switch (branch) { - case "main": + case devBranch: return "dev"; case stable: return "stable"; @@ -224,10 +215,10 @@ export const AllVersion = Object.keys(CONFIG.docs).reduce((acc, val) => { return acc; }, {} as Record>); -export function convertVersionName(version: string, stable: string) { +export function convertVersionName(version: string, stable: string, repo?: string) { + const devBranch = repo === "tidb-in-kubernetes" ? "main" : "master"; switch (version) { - case "master": - case "main": + case devBranch: return "dev"; case stable: return "stable";