Skip to content

Commit be44278

Browse files
committed
fix for gh-pages
1 parent 040dce0 commit be44278

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

bun.lockb

414 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"devDependencies": {
1616
"@sveltejs/adapter-auto": "^4.0.0",
17+
"@sveltejs/adapter-static": "^3.0.8",
1718
"@sveltejs/kit": "^2.0.0",
1819
"@sveltejs/vite-plugin-svelte": "^4.0.0",
1920
"@tailwindcss/forms": "^0.5.10",

src/404.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Single Page Apps for GitHub Pages</title>
6+
<script type="text/javascript">
7+
// Single Page Apps for GitHub Pages
8+
// MIT License
9+
// https://github.com/rafgraph/spa-github-pages
10+
// This script takes the current url and converts the path and query
11+
// string into just a query string, and then redirects the browser
12+
// to the new url with only a query string and hash fragment,
13+
// e.g. https://www.foo.tld/one/two?a=b&c=d#qwe, becomes
14+
// https://www.foo.tld/?/one/two&a=b~and~c=d#qwe
15+
// Note: this 404.html file must be at least 512 bytes for it to work
16+
// with Internet Explorer (it is currently > 512 bytes)
17+
18+
// If you're creating a Project Pages site and NOT using a custom domain,
19+
// then set pathSegmentsToKeep to 1 (enterprise users may need to set it to > 1).
20+
// This way the code will only replace the route part of the path, and not
21+
// the real directory in which the app resides, for example:
22+
// https://username.github.io/repo-name/one/two?a=b&c=d#qwe becomes
23+
// https://username.github.io/repo-name/?/one/two&a=b~and~c=d#qwe
24+
// Otherwise, leave pathSegmentsToKeep as 0.
25+
var pathSegmentsToKeep = 0;
26+
27+
var l = window.location;
28+
l.replace(
29+
l.protocol +
30+
'//' +
31+
l.hostname +
32+
(l.port ? ':' + l.port : '') +
33+
l.pathname
34+
.split('/')
35+
.slice(0, 1 + pathSegmentsToKeep)
36+
.join('/') +
37+
'/?/' +
38+
l.pathname
39+
.slice(1)
40+
.split('/')
41+
.slice(pathSegmentsToKeep)
42+
.join('/')
43+
.replace(/&/g, '~and~') +
44+
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
45+
l.hash
46+
);
47+
</script>
48+
</head>
49+
<body></body>
50+
</html>

src/app.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111
%sveltekit.head%
1212
</head>
1313
<body data-sveltekit-preload-data="hover">
14+
<script>
15+
(function (l) {
16+
if (l.search[1] === '/') {
17+
var decoded = l.search
18+
.slice(1)
19+
.split('&')
20+
.map(function (s) {
21+
return s.replace(/~and~/g, '&');
22+
})
23+
.join('?');
24+
window.history.replaceState(null, '', l.pathname.slice(0, -1) + decoded + l.hash);
25+
}
26+
})(window.location);
27+
</script>
1428
<div style="display: contents">%sveltekit.body%</div>
1529
</body>
1630
</html>

svelte.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import adapter from '@sveltejs/adapter-auto';
1+
import adapter from '@sveltejs/adapter-static';
22
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
33

44
/** @type {import('@sveltejs/kit').Config} */
@@ -11,7 +11,9 @@ const config = {
1111
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
1212
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
1313
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
14-
adapter: adapter()
14+
adapter: adapter({
15+
fallback: 'index.html'
16+
})
1517
}
1618
};
1719

0 commit comments

Comments
 (0)