-
Notifications
You must be signed in to change notification settings - Fork 4
/
redirects.js
187 lines (176 loc) · 4.31 KB
/
redirects.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// WARNING: This file is modified automatically when the `hack/make-release.sh` script is executed:
// - New version is appended to the `versions` array
// - Wherever there is a redirect with the `next: true` version rule, the new release is appended
//
// We need to maintain custom redirects as it's not handled automatically by Docusaurus: https://github.com/facebook/docusaurus/issues/3407
// NOTE: Redirects don't work in development mode. Use `npm run build` and `npm run serve` to see them in action.
//
// https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-client-redirects
const versions = [
"0.7",
"0.6",
"0.5",
"0.4",
"", // latest
"next", // unreleased
];
const latestVersion = findLatestVersion(versions);
function generateDocsRedirectsForVersions(versions) {
const redirects = [];
for (let version of versions) {
redirects.push(...generateDocsRedirectsForVersion(version));
}
return redirects;
}
function findLatestVersion(versions) {
if (!versions) {
throw new Error("versions cannot be empty");
}
return (
versions
.filter((item) => item != "" && item != "next")
// source for this basic one-line semver comparison: https://stackoverflow.com/a/65687141
.sort((a, b) =>
b.localeCompare(a, undefined, { numeric: true, sensitivity: "base" })
)[0]
);
}
function generateDocsRedirectsForVersion(version) {
const fromPrefix = version != "" ? `/docs/${version}` : "/docs";
let toPrefix = fromPrefix;
if (version === latestVersion) {
// for the latest version, redirect to URL without version number
toPrefix = "/docs";
}
const mapping = [
{
from: `${fromPrefix}`,
to: `${toPrefix}/getting-started`,
versions: {
0.5: true,
0.6: true,
0.7: true,
next: true,
},
},
{
from: `${fromPrefix}/installation`,
to: `${toPrefix}/installation/local`,
versions: {
0.4: true,
0.5: true,
0.6: true,
0.7: true,
next: true,
},
},
{
from: `${fromPrefix}/example`,
to: `${toPrefix}/example/mattermost-installation`,
versions: {
0.4: true,
0.5: true,
0.6: true,
0.7: true,
next: true,
},
},
{
from: `${fromPrefix}/content-development`,
to: `${toPrefix}/content-development/guide`,
versions: {
0.4: true,
0.5: true,
0.6: true,
0.7: true,
next: true,
},
},
{
from: `${fromPrefix}/feature`,
to: `${toPrefix}/feature/policies/overview`,
versions: {
0.4: true,
0.5: true,
0.6: true,
0.7: true,
next: true,
},
},
{
from: `${fromPrefix}/architecture`,
to: `${toPrefix}/architecture/e2e-architecture`,
versions: {
0.4: true,
0.5: true,
0.6: true,
0.7: true,
next: true,
},
},
{
from: `${fromPrefix}/cli/commands`,
to: `${toPrefix}/cli/commands/capact`,
versions: {
0.4: true,
0.5: true,
0.6: true,
0.7: true,
next: true,
},
},
{
from: `${fromPrefix}/operation`,
to: `${toPrefix}/operation/common-problems`,
versions: {
0.4: true,
0.5: true,
0.6: true,
0.7: true,
next: true,
},
},
{
from: `${fromPrefix}/cli`,
to: `${toPrefix}/cli/getting-started`,
versions: {
0.4: true,
0.5: true,
0.6: true,
0.7: true,
next: true,
},
},
{
from: `${fromPrefix}/dashboard-ui`,
to: `${toPrefix}/dashboard-ui/overview`,
versions: {
0.6: true,
0.7: true,
next: true,
},
},
// legacy redirects
{
from: `${fromPrefix}`,
to: `${toPrefix}/introduction`,
versions: {
0.4: true,
},
},
{
from: `${fromPrefix}/development`,
to: `${toPrefix}/development/development-guide`,
versions: {
0.4: true,
},
},
];
const versionToCheck = version != "" ? version : latestVersion;
return mapping
.filter((item) => item.versions[versionToCheck])
.map(({ from, to }) => ({ from, to }));
}
module.exports = () => {
return generateDocsRedirectsForVersions(versions);
};