Skip to content

Commit b4d12d5

Browse files
committed
fix dm archive url resolution
1 parent 105e318 commit b4d12d5

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

gatsby/url-resolver/__tests__/url-resolver.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,24 @@ describe("calculateFileUrl", () => {
214214
expect(url).toBe("/en/tidb/dev/page/");
215215
});
216216

217+
it("should resolve tidb-data-migration _index with release branch alias", () => {
218+
const absolutePath = path.join(
219+
sourceBasePath,
220+
"zh/tidb-data-migration/release-2.0/_index.md"
221+
);
222+
const url = calculateFileUrlWithConfig(absolutePath, testConfig);
223+
expect(url).toBe("/zh/tidb-data-migration/v2.0");
224+
});
225+
226+
it("should resolve tidb-data-migration pages with release branch alias", () => {
227+
const absolutePath = path.join(
228+
sourceBasePath,
229+
"zh/tidb-data-migration/release-2.0/overview.md"
230+
);
231+
const url = calculateFileUrlWithConfig(absolutePath, testConfig);
232+
expect(url).toBe("/zh/tidb-data-migration/v2.0/overview/");
233+
});
234+
217235
it("should resolve api folder", () => {
218236
const absolutePath = path.join(
219237
sourceBasePath,
@@ -469,6 +487,19 @@ describe("calculateFileUrl with defaultLanguage: 'en'", () => {
469487
// release-8.5 -> stable via branch-alias-tidb (exact match takes precedence)
470488
expect(url).toBe("/tidb/stable/alert-rules");
471489
});
490+
491+
it("should omit /en/ prefix for English tidb-data-migration files", () => {
492+
const absolutePath = path.join(
493+
sourceBasePath,
494+
"en/tidb-data-migration/release-5.3/dm-overview.md"
495+
);
496+
const url = calculateFileUrlWithConfig(
497+
absolutePath,
498+
configWithDefaultLang,
499+
true
500+
);
501+
expect(url).toBe("/tidb-data-migration/v5.3/dm-overview");
502+
});
472503
});
473504

474505
describe("calculateFileUrl with slug format (relative path)", () => {

gatsby/url-resolver/config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ export const defaultUrlResolverConfig: UrlResolverConfig = {
123123
ignoreIf: ["_index", "_docHome"],
124124
},
125125
},
126+
// tidb-data-migration with branch and optional folders
127+
// /en/tidb-data-migration/release-5.3/{...folders}/{filename} -> /en/tidb-data-migration/v5.3/{filename}
128+
{
129+
sourcePattern:
130+
"/{lang}/tidb-data-migration/{branch}/{...folders}/{filename}",
131+
targetPattern:
132+
"/{lang}/tidb-data-migration/{branch:branch-alias-tidb-data-migration}/{filename}",
133+
filenameTransform: {
134+
ignoreIf: ["_index", "_docHome"],
135+
},
136+
},
126137
// Fallback: /{lang}/{repo}/{...any}/{filename} -> /{lang}/{repo}/{filename}
127138
{
128139
sourcePattern: "/{lang}/{repo}/{...any}/{filename}",
@@ -164,5 +175,15 @@ export const defaultUrlResolverConfig: UrlResolverConfig = {
164175
"release-*": "v*",
165176
},
166177
},
178+
// Branch alias for tidb-data-migration: used in {branch:branch-alias-tidb-data-migration}
179+
"branch-alias-tidb-data-migration": {
180+
mappings: {
181+
// Wildcard pattern: release-* -> v*
182+
// Examples:
183+
// release-5.3 -> v5.3
184+
// release-2.0 -> v2.0
185+
"release-*": "v*",
186+
},
187+
},
167188
},
168189
};

0 commit comments

Comments
 (0)