-
Notifications
You must be signed in to change notification settings - Fork 23
/
404.html
57 lines (52 loc) · 2.94 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
<html lang="en">
<head>
<script>
let finalBaseHref = location.origin; // root
const showcaseRegex = /\/showcase(\/|.*)/;
const apiDocsRegex = /\/api-docs(\/|.*)/;
const versionsRegexStr = "((\\\d+\\\.\\\d+\\\.\\\d(-alpha\\\.\\\d+|-beta\\\.\\\d+)?)|latest)";
const isShowcase = !!showcaseRegex.exec(window.location.pathname);
const isApiDocs = !!apiDocsRegex.exec(window.location.pathname);
if (isShowcase) {
const showcaseVersionsRegex = new RegExp("/showcase/" + versionsRegexStr);
const showcaseVersion = showcaseVersionsRegex.exec(window.location.pathname);
if (showcaseVersion) {
// if a version was detected, then go to the root of that version in order to load the Angular app
finalBaseHref = finalBaseHref + showcaseVersion[0];
// also store the original URL in sessionStorage so that the Angular app navigates to it and handles the wrong path
sessionStorage.redirect = location.href;
} else {
// in case no version was detected, then go to "latest"
finalBaseHref = finalBaseHref + "/showcase/latest/";
sessionStorage.redirect = finalBaseHref;
}
} else if (isApiDocs) {
const apiDocsPackagesRegexStr = "/api-docs/stark-(build|testing|core|ui)\/";
const apiDocsVersionsRegex = new RegExp(apiDocsPackagesRegexStr + versionsRegexStr);
const apiDocsVersion = apiDocsVersionsRegex.exec(window.location.pathname);
if (apiDocsVersion) {
// if a version was detected, then go to the root of that version
finalBaseHref = finalBaseHref + apiDocsVersion[0];
sessionStorage.redirect = finalBaseHref;
} else {
const apiDocsPackage = window.location.pathname.match(apiDocsPackagesRegexStr);
if (apiDocsPackage) {
// in case only the package was detected, then go to that package "latest"
finalBaseHref = finalBaseHref + apiDocsPackage[0] + "/latest/";
sessionStorage.redirect = finalBaseHref;
} else {
// in case no version nor package was detected, then go to "stark-core/latest"
finalBaseHref = finalBaseHref + "/api-docs/stark-core/latest/";
sessionStorage.redirect = finalBaseHref;
}
}
} else {
// url does not match showcase nor API docs, so go to the root
sessionStorage.redirect = finalBaseHref;
}
window.open(finalBaseHref, "_self"); // redirection
</script>
<!-- We don't use the meta tag for the moment, to make the refresh more dynamic with every release of the showcase (alphas, betas, latest, ...)-->
<!--<meta http-equiv="refresh" content="0;URL='/showcase/latest'"></meta>-->
</head>
</html>