-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathpathTransfer.ts
More file actions
71 lines (68 loc) · 3.24 KB
/
pathTransfer.ts
File metadata and controls
71 lines (68 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const transformPathWithoutZhCN = (pathname: string): string => {
if (pathname.startsWith('/docs-next/')) {
return `/docs-next${pathname.replace('/docs-next/dev', '')}.md`;
}
if(pathname.startsWith('/docs')){
const pathWithoutDocs = pathname.replace('/docs', '');
if(pathname.includes('/4.x')){
return `/versioned_docs/version-4.x${pathWithoutDocs.replace('/4.x', '')}.md`;
}else if (pathname.includes('/3.x')) {
return `/versioned_docs/version-3.x${pathWithoutDocs.replace('/3.x', '')}.md`;
} else if (pathname.includes('/2.0')) {
return `/versioned_docs/version-2.0${pathWithoutDocs.replace('/2.0', '')}.md`;
} else if (pathname.includes('/1.2')) {
return `/versioned_docs/version-1.2${pathWithoutDocs.replace('/1.2', '')}.md`;
} else if (pathname.includes('/dev')) {
return `/docs${pathWithoutDocs.replace('/dev', '')}.md`;
} else {
return `/versioned_docs/version-2.1${pathWithoutDocs}.md`;
}
}else{
// community
return `${pathname}.md`
}
};
const stripLocalePrefix = (pathname: string): string => {
const segments = pathname.split('/').filter(Boolean);
if (segments.length === 0) {
return pathname;
}
if (/^[a-z]{2}(?:-[A-Z]{2})?$/.test(segments[0])) {
return `/${segments.slice(1).join('/')}`;
}
return pathname;
};
const transformPathWithZhCN = (pathname: string): string => {
if (pathname.startsWith('/zh-CN/docs-next/')) {
return `/i18n/zh-CN/docusaurus-plugin-content-docs-next/current${pathname.replace('/zh-CN/docs-next/dev', '')}.md`;
}
if (pathname.startsWith('/zh-CN/docs')) {
if(pathname.includes('/4.x')){
return `/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x${pathname.replace('/zh-CN/docs/4.x', '')}.md`;
}else if (pathname.includes('/3.x')) {
return `/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.x${pathname.replace('/zh-CN/docs/3.x', '')}.md`;
} else if (pathname.includes('/2.0')) {
return `/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0${pathname.replace('/zh-CN/docs/2.0', '')}.md`;
} else if (pathname.includes('/1.2')) {
return `/i18n/zh-CN/docusaurus-plugin-content-docs/version-1.2${pathname.replace('/zh-CN/docs/1.2', '')}.md`;
} else if (pathname.includes('/dev')) {
return `/i18n/zh-CN/docusaurus-plugin-content-docs/current${pathname.replace('/zh-CN/docs/dev', '')}.md`;
} else {
return `/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1${pathname.replace('/zh-CN/docs', '')}.md`;;
}
} else {
// community
return `/i18n/zh-CN/docusaurus-plugin-content-docs-community/current${pathname.replace('/zh-CN/community','')}.md`
}
}
const transformDocPath = (pathname: string): string => {
if (pathname.startsWith('/zh-CN')) {
return transformPathWithZhCN(pathname)
} else {
return transformPathWithoutZhCN(stripLocalePrefix(pathname));
}
};
export const generateUrl = (pathname: string): string => {
const transformedPath = transformDocPath(pathname);
return `https://github.com/apache/doris-website/tree/master${transformedPath}`;
};