Skip to content

Commit 04a9edd

Browse files
committed
Fixed added rerouting
1 parent 68b4cbd commit 04a9edd

6 files changed

Lines changed: 135 additions & 12 deletions

File tree

404.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Redirecting...</title>
6+
</head>
7+
<body>
8+
<script>
9+
// Single Page Apps for GitHub Pages
10+
// MIT License
11+
// https://github.com/rafgraph/spa-github-pages
12+
// This script takes the current url and converts the path and query
13+
// string into just a query string, and then redirects the browser
14+
// to the new url with only a query string and hash fragment.
15+
var pathSegmentsToKeep = 0;
16+
17+
var l = window.location;
18+
l.replace(
19+
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
20+
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
21+
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
22+
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
23+
l.hash
24+
);
25+
</script>
26+
</body>
27+
</html>

Source code/index.html

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<!DOCTYPE html>
32
<html lang="en">
43
<head>
@@ -23,6 +22,31 @@
2322
<div id="root"></div>
2423
<!-- IMPORTANT: DO NOT REMOVE THIS SCRIPT TAG OR THIS VERY COMMENT! -->
2524
<script src="https://cdn.gpteng.co/gptengineer.js" type="module"></script>
25+
26+
<!-- GitHub Pages SPA redirect script -->
27+
<script>
28+
// Single Page Apps for GitHub Pages
29+
// MIT License
30+
// https://github.com/rafgraph/spa-github-pages
31+
// This script checks to see if a redirect is present in the query string,
32+
// converts it back into the correct url and adds it to the
33+
// browser's history using window.history.replaceState(...),
34+
// which won't cause the browser to attempt to load the new url.
35+
// When the single page app is loaded further down in this file,
36+
// the correct url will be waiting in the browser's history for
37+
// the single page app to route accordingly.
38+
(function(l) {
39+
if (l.search[1] === '/' ) {
40+
var decoded = l.search.slice(1).split('&').map(function(s) {
41+
return s.replace(/~and~/g, '&')
42+
}).join('?');
43+
window.history.replaceState(null, null,
44+
l.pathname.slice(0, -1) + decoded + l.hash
45+
);
46+
}
47+
}(window.location))
48+
</script>
49+
2650
<script type="module" src="/src/main.tsx"></script>
2751
</body>
2852
</html>

Source code/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
"build": "bunx vite build",
99
"build:dev": "bunx vite build --mode development",
1010
"lint": "bunx eslint .",
11-
"preview": "bunx vite preview"
11+
"preview": "bunx vite preview",
12+
"dev:npm": "vite",
13+
"build:npm": "vite build",
14+
"build:dev:npm": "vite build --mode development",
15+
"lint:npm": "eslint .",
16+
"preview:npm": "vite preview"
1217
},
1318
"dependencies": {
1419
"@hookform/resolvers": "^3.9.0",

Source code/public/404.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Redirecting...</title>
6+
</head>
7+
<body>
8+
<script>
9+
// Single Page Apps for GitHub Pages
10+
// MIT License
11+
// https://github.com/rafgraph/spa-github-pages
12+
// This script takes the current url and converts the path and query
13+
// string into just a query string, and then redirects the browser
14+
// to the new url with only a query string and hash fragment.
15+
var pathSegmentsToKeep = 0;
16+
17+
var l = window.location;
18+
l.replace(
19+
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
20+
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
21+
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
22+
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
23+
l.hash
24+
);
25+
</script>
26+
</body>
27+
</html>

Source code/workflows/static.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,38 @@ concurrency:
2222
cancel-in-progress: false
2323

2424
jobs:
25-
# Single deploy job since we're just deploying
26-
deploy:
27-
environment:
28-
name: github-pages
29-
url: ${{ steps.deployment.outputs.page_url }}
25+
# Build job
26+
build:
3027
runs-on: ubuntu-latest
3128
steps:
3229
- name: Checkout
3330
uses: actions/checkout@v4
34-
- name: Setup Pages
35-
uses: actions/configure-pages@v5
31+
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: '18'
36+
37+
- name: Install dependencies
38+
run: npm ci
39+
40+
- name: Build project
41+
run: npm run build:npm
42+
3643
- name: Upload artifact
3744
uses: actions/upload-pages-artifact@v3
3845
with:
39-
# Upload entire repository
40-
path: '.'
46+
# Upload dist folder
47+
path: './dist'
48+
49+
# Deploy job
50+
deploy:
51+
environment:
52+
name: github-pages
53+
url: ${{ steps.deployment.outputs.page_url }}
54+
runs-on: ubuntu-latest
55+
needs: build
56+
steps:
4157
- name: Deploy to GitHub Pages
4258
id: deployment
4359
uses: actions/deploy-pages@v4

index.html

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<!DOCTYPE html>
32
<html lang="en">
43
<head>
@@ -25,5 +24,30 @@
2524
<div id="root"></div>
2625
<!-- IMPORTANT: DO NOT REMOVE THIS SCRIPT TAG OR THIS VERY COMMENT! -->
2726
<script src="https://cdn.gpteng.co/gptengineer.js" type="module"></script>
27+
28+
<!-- GitHub Pages SPA redirect script -->
29+
<script>
30+
// Single Page Apps for GitHub Pages
31+
// MIT License
32+
// https://github.com/rafgraph/spa-github-pages
33+
// This script checks to see if a redirect is present in the query string,
34+
// converts it back into the correct url and adds it to the
35+
// browser's history using window.history.replaceState(...),
36+
// which won't cause the browser to attempt to load the new url.
37+
// When the single page app is loaded further down in this file,
38+
// the correct url will be waiting in the browser's history for
39+
// the single page app to route accordingly.
40+
(function(l) {
41+
if (l.search[1] === '/' ) {
42+
var decoded = l.search.slice(1).split('&').map(function(s) {
43+
return s.replace(/~and~/g, '&')
44+
}).join('?');
45+
window.history.replaceState(null, null,
46+
l.pathname.slice(0, -1) + decoded + l.hash
47+
);
48+
}
49+
}(window.location))
50+
</script>
51+
2852
</body>
2953
</html>

0 commit comments

Comments
 (0)