Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions gatsby/url-resolver/__tests__/url-resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,42 @@ describe("calculateFileUrl", () => {
expect(url).toBe("/en/tidb/dev/page/");
});

it("should resolve tidb-data-migration _index with release branch alias", () => {
const absolutePath = path.join(
sourceBasePath,
"zh/tidb-data-migration/release-2.0/_index.md"
);
const url = calculateFileUrlWithConfig(absolutePath, testConfig);
expect(url).toBe("/zh/tidb-data-migration/v2.0");
});

it("should resolve tidb-data-migration pages with release branch alias", () => {
const absolutePath = path.join(
sourceBasePath,
"zh/tidb-data-migration/release-2.0/overview.md"
);
const url = calculateFileUrlWithConfig(absolutePath, testConfig);
expect(url).toBe("/zh/tidb-data-migration/v2.0/overview/");
});

it("should resolve tidb-data-migration v1.0 pages with release branch alias", () => {
const absolutePath = path.join(
sourceBasePath,
"zh/tidb-data-migration/release-1.0/overview.md"
);
const url = calculateFileUrlWithConfig(absolutePath, testConfig);
expect(url).toBe("/zh/tidb-data-migration/v1.0/overview/");
});

it("should resolve tidb-data-migration nested _index with folders", () => {
const absolutePath = path.join(
sourceBasePath,
"zh/tidb-data-migration/release-2.0/releases/_index.md"
);
const url = calculateFileUrlWithConfig(absolutePath, testConfig);
expect(url).toBe("/zh/tidb-data-migration/v2.0/releases");
});

it("should resolve api folder", () => {
const absolutePath = path.join(
sourceBasePath,
Expand Down Expand Up @@ -469,6 +505,61 @@ describe("calculateFileUrl with defaultLanguage: 'en'", () => {
// release-8.5 -> stable via branch-alias-tidb (exact match takes precedence)
expect(url).toBe("/tidb/stable/alert-rules");
});

it("should omit /en/ prefix for English tidb-data-migration files", () => {
const absolutePath = path.join(
sourceBasePath,
"en/tidb-data-migration/release-5.3/dm-overview.md"
);
const url = calculateFileUrlWithConfig(
absolutePath,
configWithDefaultLang,
true
);
expect(url).toBe("/tidb-data-migration/v5.3/dm-overview");
});

it("should omit /en/ prefix for English tidb-data-migration release indexes", () => {
const cases = [
["release-5.3", "/tidb-data-migration/v5.3"],
["release-2.0", "/tidb-data-migration/v2.0"],
["release-1.0", "/tidb-data-migration/v1.0"],
];

for (const [branch, expected] of cases) {
const absolutePath = path.join(
sourceBasePath,
`en/tidb-data-migration/${branch}/_index.md`
);
const url = calculateFileUrlWithConfig(
absolutePath,
configWithDefaultLang,
true
);
expect(url).toBe(expected);
}
});

it("should keep /zh/ prefix for Chinese tidb-data-migration release indexes", () => {
const cases = [
["release-5.3", "/zh/tidb-data-migration/v5.3"],
["release-2.0", "/zh/tidb-data-migration/v2.0"],
["release-1.0", "/zh/tidb-data-migration/v1.0"],
];

for (const [branch, expected] of cases) {
const absolutePath = path.join(
sourceBasePath,
`zh/tidb-data-migration/${branch}/_index.md`
);
const url = calculateFileUrlWithConfig(
absolutePath,
configWithDefaultLang,
true
);
expect(url).toBe(expected);
}
});
});

describe("calculateFileUrl with slug format (relative path)", () => {
Expand Down
32 changes: 32 additions & 0 deletions gatsby/url-resolver/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,28 @@ export const defaultUrlResolverConfig: UrlResolverConfig = {
ignoreIf: ["_index", "_docHome"],
},
},
// tidb-data-migration index pages with folders (avoid URL collision)
{
sourcePattern:
"/{lang}/tidb-data-migration/{branch}/{...folders}/{filename}",
targetPattern:
"/{lang}/tidb-data-migration/{branch:branch-alias-tidb-data-migration}/{folders}",
conditions: { filename: ["_index"] },
filenameTransform: {
ignoreIf: ["_index"],
},
},
// tidb-data-migration with branch and optional folders
// /en/tidb-data-migration/release-5.3/{...folders}/{filename} -> /en/tidb-data-migration/v5.3/{filename}
{
sourcePattern:
"/{lang}/tidb-data-migration/{branch}/{...folders}/{filename}",
targetPattern:
"/{lang}/tidb-data-migration/{branch:branch-alias-tidb-data-migration}/{filename}",
filenameTransform: {
ignoreIf: ["_index", "_docHome"],
},
},
Comment thread
qiancai marked this conversation as resolved.
// Fallback: /{lang}/{repo}/{...any}/{filename} -> /{lang}/{repo}/{filename}
{
sourcePattern: "/{lang}/{repo}/{...any}/{filename}",
Expand Down Expand Up @@ -164,5 +186,15 @@ export const defaultUrlResolverConfig: UrlResolverConfig = {
"release-*": "v*",
},
},
// Branch alias for tidb-data-migration: used in {branch:branch-alias-tidb-data-migration}
"branch-alias-tidb-data-migration": {
mappings: {
// Wildcard pattern: release-* -> v*
// Examples:
// release-5.3 -> v5.3
// release-2.0 -> v2.0
"release-*": "v*",
},
},
},
};