Skip to content

Commit 8eea59e

Browse files
committed
refactor: simplify URL generation logic in createDocs and path handling
- Removed conditional logic for URL generation in createDocs, streamlining the process to always use the name directly. - Updated path handling in generateConfig to ensure consistent naming for different repo types, enhancing clarity and maintainability.
1 parent b14d522 commit 8eea59e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

gatsby/create-pages.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from "./path";
1515
import { docs as DOCS_CONFIG } from "../docs/docs.json";
1616
import { cpMarkdown } from "./cp-markdown";
17-
import { queryTOCs } from "./toc";
1817

1918
interface PageQueryData {
2019
allMdx: {
@@ -100,11 +99,7 @@ export const createDocs = async (createPagesArgs: CreatePagesArgs) => {
10099
return;
101100
}
102101

103-
const path = filePath.includes("starter")
104-
? generateUrl(`starter/${name}`, pathConfig)
105-
: filePath.includes("essential")
106-
? generateUrl(`essential/${name}`, pathConfig)
107-
: generateUrl(name, pathConfig);
102+
const path = generateUrl(name, pathConfig);
108103
const navUrl = generateNav(pathConfig);
109104
const starterNavUrl = generateStarterNav(pathConfig);
110105
const essentialNavUrl = generateEssentialNav(pathConfig);

gatsby/path.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,30 @@ export function generateConfig(slug: string): {
4747
...string[]
4848
];
4949

50-
const name = rest[rest.length - 1];
51-
5250
let filePath = rest.join("/") + ".md";
5351
if (repo === Repo.dm || repo === Repo.operator) {
5452
filePath = `${locale}/${filePath}`;
5553
}
5654

55+
let name = rest[rest.length - 1];
56+
name = name === "_index" ? "" : name;
57+
58+
if (repo === Repo.tidbcloud) {
59+
if (filePath.includes("starter/")) {
60+
name = `starter/${name}`;
61+
} else if (filePath.includes("essential/")) {
62+
name = `essential/${name}`;
63+
} else if (filePath.includes("dedicated/")) {
64+
if (!!name) {
65+
name = `dedicated/${name}`;
66+
}
67+
}
68+
}
69+
5770
return {
5871
config: { locale, repo, branch, version: branchToVersion(repo, branch) },
5972
filePath,
60-
name: name === "_index" ? "" : name,
73+
name,
6174
};
6275
}
6376

0 commit comments

Comments
 (0)