This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path404.html
49 lines (41 loc) · 1.58 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>404</title>
</head>
<body>
<script>
;
(function (l, projectPages) {
var repo = projectPages ? '/' + l.pathname.split('/')[1] : ''
/* redirect all 404 trafic to index.html */
function redirect() {
l.replace(l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + repo + '/?' +
(l.pathname ? 'p=' + l.pathname.replace(/&/g, '~and~').replace(repo, '') : '') +
(l.search ? '&q=' + l.search.slice(1).replace(/&/g, '~and~') : '') +
(l.hash))
}
/* resolve 404 redirects into internal routes */
function resolve() {
if (l.search) {
var q = {}
l.search.slice(1).split('&').forEach(function (v) {
var a = v.split('=')
q[a[0]] = a.slice(1).join('=').replace(/~and~/g, '&')
})
if (q.p !== undefined) {
window.history.replaceState(null, null,
repo + (q.p || '') +
(q.q ? ('?' + q.q) : '') +
l.hash
)
}
}
}
/* if current document is 404 page page, redirect to index.html otherwise resolve */
document.title === '404' ? redirect() : resolve()
}(window.location, window.projectPages || true))
</script>
</body>
</html>