Skip to content

Commit bf50ca4

Browse files
committed
Add GitHub Pages SPA trick
1 parent f7de6a1 commit bf50ca4

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

404.html

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>Single Page Apps for GitHub Pages</title>
7+
<script type="text/javascript">
8+
// Single Page Apps for GitHub Pages
9+
// MIT License
10+
// https://github.com/rafgraph/spa-github-pages
11+
var pathSegmentsToKeep = 0;
12+
13+
var l = window.location;
14+
l.replace(
15+
l.protocol +
16+
"//" +
17+
l.hostname +
18+
(l.port ? ":" + l.port : "") +
19+
l.pathname
20+
.split("/")
21+
.slice(0, 1 + pathSegmentsToKeep)
22+
.join("/") +
23+
"/?/" +
24+
l.pathname
25+
.slice(1)
26+
.split("/")
27+
.slice(pathSegmentsToKeep)
28+
.join("/")
29+
.replace(/&/g, "~and~") +
30+
(l.search ? "&" + l.search.slice(1).replace(/&/g, "~and~") : "") +
31+
l.hash,
32+
);
33+
</script>
34+
</head>
35+
36+
<body></body>
37+
38+
</html>

index.html

+22
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
<head>
55
<title>lukechu</title>
66
<link data-trunk rel="tailwind-css" href="assets/index.scss" />
7+
<link data-trunk rel="copy-file" href="404.html" />
8+
<script type="text/javascript">
9+
// Single Page Apps for GitHub Pages
10+
// MIT License
11+
// https://github.com/rafgraph/spa-github-pages
12+
(function (l) {
13+
if (l.search[1] === "/") {
14+
var decoded = l.search
15+
.slice(1)
16+
.split("&")
17+
.map(function (s) {
18+
return s.replace(/~and~/g, "&");
19+
})
20+
.join("?");
21+
window.history.replaceState(
22+
null,
23+
null,
24+
l.pathname.slice(0, -1) + decoded + l.hash,
25+
);
26+
}
27+
})(window.location);
28+
</script>
729
</head>
830

931
<body></body>

0 commit comments

Comments
 (0)