Skip to content

Commit 7baa094

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

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,33 @@ 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+
235+
it("should resolve tidb-data-migration v1.0 pages with release branch alias", () => {
236+
const absolutePath = path.join(
237+
sourceBasePath,
238+
"zh/tidb-data-migration/release-1.0/overview.md"
239+
);
240+
const url = calculateFileUrlWithConfig(absolutePath, testConfig);
241+
expect(url).toBe("/zh/tidb-data-migration/v1.0/overview/");
242+
});
243+
217244
it("should resolve api folder", () => {
218245
const absolutePath = path.join(
219246
sourceBasePath,
@@ -469,6 +496,61 @@ describe("calculateFileUrl with defaultLanguage: 'en'", () => {
469496
// release-8.5 -> stable via branch-alias-tidb (exact match takes precedence)
470497
expect(url).toBe("/tidb/stable/alert-rules");
471498
});
499+
500+
it("should omit /en/ prefix for English tidb-data-migration files", () => {
501+
const absolutePath = path.join(
502+
sourceBasePath,
503+
"en/tidb-data-migration/release-5.3/dm-overview.md"
504+
);
505+
const url = calculateFileUrlWithConfig(
506+
absolutePath,
507+
configWithDefaultLang,
508+
true
509+
);
510+
expect(url).toBe("/tidb-data-migration/v5.3/dm-overview");
511+
});
512+
513+
it("should omit /en/ prefix for English tidb-data-migration release indexes", () => {
514+
const cases = [
515+
["release-5.3", "/tidb-data-migration/v5.3"],
516+
["release-2.0", "/tidb-data-migration/v2.0"],
517+
["release-1.0", "/tidb-data-migration/v1.0"],
518+
];
519+
520+
for (const [branch, expected] of cases) {
521+
const absolutePath = path.join(
522+
sourceBasePath,
523+
`en/tidb-data-migration/${branch}/_index.md`
524+
);
525+
const url = calculateFileUrlWithConfig(
526+
absolutePath,
527+
configWithDefaultLang,
528+
true
529+
);
530+
expect(url).toBe(expected);
531+
}
532+
});
533+
534+
it("should keep /zh/ prefix for Chinese tidb-data-migration release indexes", () => {
535+
const cases = [
536+
["release-5.3", "/zh/tidb-data-migration/v5.3"],
537+
["release-2.0", "/zh/tidb-data-migration/v2.0"],
538+
["release-1.0", "/zh/tidb-data-migration/v1.0"],
539+
];
540+
541+
for (const [branch, expected] of cases) {
542+
const absolutePath = path.join(
543+
sourceBasePath,
544+
`zh/tidb-data-migration/${branch}/_index.md`
545+
);
546+
const url = calculateFileUrlWithConfig(
547+
absolutePath,
548+
configWithDefaultLang,
549+
true
550+
);
551+
expect(url).toBe(expected);
552+
}
553+
});
472554
});
473555

474556
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)