-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path404.html
More file actions
39 lines (35 loc) · 1.05 KB
/
404.html
File metadata and controls
39 lines (35 loc) · 1.05 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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Redirecting...</title>
</head>
<body>
<p>Redirecting to preview...</p>
<script>
const arePathsEqual = (pathA, pathB) => {
const normalize = (path) => path.replace(/^\/+|\/+$/g, '');
return normalize(pathA) === normalize(pathB);
};
const redirect = (pathname) => {
// Avoid infinite redirect loops
if (arePathsEqual(pathname, window.location.pathname)) {
document.body.innerHTML = '<p>Error: 404 Page not found</p>';
return;
}
window.location.href = pathname;
};
// Get the path from the URL
const path = window.location.pathname.split('/').filter(Boolean);
const repo = path[0];
if (path.length === 1) {
// At repo root, redirect to main
redirect(`/${repo}/main/`);
} else {
// Try the branch preview once
const branchPath = path[1];
redirect(`/${repo}/${branchPath}/index.html`);
}
</script>
</body>
</html>