-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
78 lines (76 loc) · 2.42 KB
/
Copy pathindex.html
File metadata and controls
78 lines (76 loc) · 2.42 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Redirecting...</title>
<script type="text/javascript">
var pathSegmentsToKeep = 0;
// Keep this list in sync with `src/app/router/routesConfig.jsx`.
var spaSingleSegmentRoutes = ["20240109"];
// Explicit GitHub project pages repos that should not fall back to this SPA root.
var projectPagesRepos = ["alfred-api"];
var l = window.location;
var trimmedPath = l.pathname.replace(/^\/+|\/+$/g, "");
var isSingleSegment = trimmedPath && trimmedPath.indexOf("/") === -1;
var isKnownSpaRoute = spaSingleSegmentRoutes.indexOf(trimmedPath) !== -1;
var decodedTrimmedPath;
try {
decodedTrimmedPath = decodeURIComponent(trimmedPath);
} catch (e) {
decodedTrimmedPath = trimmedPath;
}
var normalizedSegment = decodedTrimmedPath
.toLowerCase()
.replace(/\s+/g, "-")
.replace(/_/g, "-");
var isKnownProjectPagesRepo =
projectPagesRepos.indexOf(normalizedSegment) !== -1;
var hasTrailingSlash = l.pathname.charAt(l.pathname.length - 1) === "/";
if (isKnownProjectPagesRepo && !hasTrailingSlash) {
l.replace(
l.protocol +
"//" +
l.hostname +
(l.port ? ":" + l.port : "") +
"/" +
trimmedPath +
"/" +
l.search +
l.hash,
);
}
// For unknown top-level paths like `/some-repo`, try GitHub Pages project URL first.
else if (isSingleSegment && !isKnownSpaRoute && !hasTrailingSlash) {
l.replace(
l.protocol +
"//" +
l.hostname +
(l.port ? ":" + l.port : "") +
"/" +
trimmedPath +
"/" +
l.search +
l.hash,
);
} else {
l.replace(
l.protocol +
"//" +
l.hostname +
(l.port ? ":" + l.port : "") +
l.pathname.split("/").slice(0, 1 + pathSegmentsToKeep).join("/") +
"/?/" +
l.pathname
.slice(1)
.split("/")
.slice(pathSegmentsToKeep)
.join("/")
.replace(/&/g, "~and~") +
(l.search ? "&" + l.search.slice(1).replace(/&/g, "~and~") : "") +
l.hash,
);
}
</script>
</head>
<body></body>
</html>