-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathredirects.js
118 lines (109 loc) · 5.06 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
// 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 fs = require("fs");
const subPathsToRedirect = ["/docs", "/community"];
let versions;
/**
* @return {string[]}
*/
function getVersions() {
if (!Array.isArray(versions)) {
try {
versions = JSON.parse(String(fs.readFileSync("./versions.json")));
versions.push("next");
} catch {
versions = ["next"];
}
}
return versions;
}
/**
* @param {string} path
* @return boolean
*/
function hasVersionInPath(path) {
const versions = getVersions();
return versions.some(ver => path.includes(ver));
}
/**
* @param {string} existingPath
* @return {string[]|undefined}
*/
function createRedirects(existingPath) {
if (!hasVersionInPath(existingPath)) {
for (const subPath of subPathsToRedirect) {
if (existingPath.includes(subPath)) {
return [existingPath.replace(subPath, "")];
}
}
}
return undefined;
}
/**
* @return {{to: string, from: string}[]}
*/
function customRedirections() {
return [
// old links
{ from: "/docs", to: "/" },
{ from: "/installation", to: "/" },
{ from: "/community", to: "/community/contribute/" },
{ from: "/filters", to: "/plugins/kubernetes" },
// v1.10->v1.11 links
{ from: "/configuration/", to: "/self-hosted-configuration" },
{ from: "/configuration/action", to: "/features/actions" },
{ from: "/configuration/alias", to: "/features/executing-commands" },
{ from: "/configuration/communication/", to: "/self-hosted-configuration/communication" },
{ from: "/configuration/communication/vault-csi", to: "/self-hosted-configuration/communication/vault-csi" },
{ from: "/configuration/executor/", to: "/plugins" },
{ from: "/configuration/executor/doctor", to: "/plugins/ai-assistant" },
{ from: "/configuration/executor/exec", to: "/plugins/exec" },
{ from: "/configuration/executor/flux", to: "/plugins/flux" },
{ from: "/configuration/executor/helm", to: "/plugins/helm" },
{ from: "/configuration/executor/kubectl", to: "/plugins/kubectl" },
{ from: "/configuration/general", to: "/self-hosted-configuration/general" },
{ from: "/configuration/helm-chart-parameters", to: "/self-hosted-configuration/helm-chart-parameters" },
{ from: "/configuration/rbac", to: "/features/rbac" },
{ from: "/configuration/source/", to: "/plugins" },
{ from: "/configuration/source/argocd", to: "/plugins/argocd" },
{ from: "/configuration/source/github-events", to: "/plugins/github-events" },
{ from: "/configuration/source/keptn", to: "/plugins/keptn" },
{ from: "/configuration/source/kubernetes", to: "/plugins/kubernetes" },
{ from: "/configuration/source/prometheus", to: "/plugins/prometheus" },
{ from: "/usage/", to: "/features/executing-commands" },
{ from: "/usage/automated-actions", to: "/features/actions" },
{ from: "/usage/event-notifications", to: "/features/event-notifications" },
{ from: "/usage/executor/", to: "/plugins" },
{ from: "/usage/executor/doctor", to: "/plugins/ai-assistant" },
{ from: "/usage/executor/exec", to: "/plugins/exec" },
{ from: "/usage/executor/flux", to: "/plugins/flux" },
{ from: "/usage/executor/helm", to: "/plugins/helm" },
{ from: "/usage/executor/kubectl", to: "/plugins/kubectl" },
{ from: "/usage/interactive-output-filtering", to: "/features/executing-commands" },
{ from: "/usage/source/", to: "/plugins" },
{ from: "/usage/source/argocd", to: "/plugins/argocd" },
{ from: "/usage/source/keptn", to: "/plugins/keptn" },
{ from: "/usage/source/kubernetes", to: "/plugins/kubernetes" },
{ from: "/usage/source/prometheus", to: "/plugins/prometheus" },
{ from: "/plugin/", to: "/plugins/development/" },
{ from: "/plugin/custom-executor", to: "/plugins/development/custom-executor" },
{ from: "/plugin/custom-source", to: "/plugins/development/custom-source" },
{ from: "/plugin/debugging", to: "/plugins/development/debugging" },
{ from: "/plugin/dependencies", to: "/plugins/development/dependencies" },
{ from: "/plugin/interactive-messages", to: "/plugins/development/interactive-messages" },
{ from: "/plugin/local-testing", to: "/plugins/development/local-testing" },
{ from: "/plugin/quick-start", to: "/plugins/development/quick-start" },
{ from: "/plugin/repo", to: "/plugins/development/repo" },
{ from: "/plugin/troubleshooting.md", to: "/plugins/development/troubleshooting" },
{ from: "/plugin/using-kubeconfig", to: "/plugins/development/using-kubeconfig" },
{ from: "/operation/diagnostics", to: "/troubleshooting/diagnostics" },
{ from: "/operation/common-problems", to: "/troubleshooting/common-problems" },
{ from: "/privacy", to: "https://botkube.io/privacy-policy" },
];
}
module.exports = {
redirects: customRedirections(),
createRedirects,
};