-
Notifications
You must be signed in to change notification settings - Fork 11
/
404.html
118 lines (111 loc) · 3.83 KB
/
404.html
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
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous"
/>
<title>Page not found</title>
<script>
function isAstarteDeviceSDKUrl(url) {
return /\/(snapshot|latest|\d\.\d\d?)\/device-sdks\//.test(url);
}
function redirectAstarteDeviceSDKUrl(url) {
const redirectedUrl = url.replace(
/\/(snapshot|latest|\d\.\d\d?)\/device-sdks\/([^/]+)\//,
(fullMatch, version, sdkName) =>
`/device-sdks/${sdkName}/${version}/api/`
);
if (
redirectedUrl === url ||
/\/device-sdks\/([^/]+)\/(snapshot|latest|\d\.\d\d?)\//.test(url)
) {
// url was already redirected
return null;
}
return redirectedUrl;
}
function isAstarteFlowUrl(url) {
return /\/flow\/(snapshot|latest|\d\.\d\d?)\//.test(url);
}
function redirectAstarteFlowUrl(url) {
// Docs structure was not changed for Flow.
// Since the user landed on this 404 page, the original page does not exist anymore
return null;
}
function isAstarteOperatorUrl(url) {
const astarteOperatorPages = [
"000-upgrade_index.html",
"010-upgrade_010_011.html",
"020-upgrade_011_10.html",
"030-upgrade_100_10x.html",
];
return astarteOperatorPages.some((page) => url.includes(page));
}
function redirectAstarteOperatorUrl(url) {
const redirectedUrl = url.replace(
/\/(snapshot|latest|\d\.\d\d?)\//,
"/astarte-kubernetes-operator/latest/"
);
if (
redirectedUrl === url ||
url.includes("/astarte-kubernetes-operator/latest/")
) {
// url was already redirected
return null;
}
return redirectedUrl;
}
function redirectAstarteUrl(url) {
const redirectedUrl = url.replace(
/\/(snapshot|latest|\d\.\d\d?)\//,
(fullMatch, version) => `/astarte/${version}/`
);
if (
redirectedUrl === url ||
/\/astarte\/(snapshot|latest|\d\.\d\d?)\//.test(url)
) {
// url was already redirected
return null;
}
return redirectedUrl;
}
window.onload = function () {
const url = window.location.href;
console.log(`Computing redirect for url ${url}...`);
let redirectedUrl = null;
try {
if (isAstarteOperatorUrl(url)) {
redirectedUrl = redirectAstarteOperatorUrl(url);
} else if (isAstarteDeviceSDKUrl(url)) {
redirectedUrl = redirectAstarteDeviceSDKUrl(url);
} else if (isAstarteFlowUrl(url)) {
redirectedUrl = redirectAstarteFlowUrl(url);
} else {
redirectedUrl = redirectAstarteUrl(url);
}
} catch (error) {
console.log("Error while computing redirect", error);
} finally {
redirectedUrl = redirectedUrl || window.location.origin;
console.log(`Will redirect to ${redirectedUrl}`);
window.location.href = redirectedUrl || window.location.origin;
}
};
</script>
</head>
<body>
<div>
<h1 class="text-center text-secondary fw-bold m-4">Page not found</h1>
<p class="text-center text-black-50 fs-5">
If you're not automatically redirect,
<a class="link" href="/">click here</a> to go back to the documentation.
</p>
</div>
</body>
</html>