Skip to content

Commit 1685d3b

Browse files
puffcocosclaude
andcommitted
(ci): ๐Ÿ› GitHub Pages SPA ๋ผ์šฐํŒ… ์ง€์› ์ถ”๊ฐ€
GitHub Pages์—์„œ ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ๋ผ์šฐํŒ…์ด ์ž‘๋™ํ•˜๋„๋ก 404.html ๋ฐ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ๋กœ์ง์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค. - rafgraph/spa-github-pages ๋ฐฉ์‹ ์ ์šฉ - 404.html ์ƒ์„ฑ: ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ๋กœ ์ ‘๊ทผ ์‹œ ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ - index.html์— ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ์Šคํฌ๋ฆฝํŠธ ์ถ”๊ฐ€: ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์›๋ž˜ ๊ฒฝ๋กœ๋กœ ๋ณต์› - pathSegmentsToKeep = 1 ์„ค์ • (Project Pages ๋Œ€์‘) ์ด์ œ /example ๊ฒฝ๋กœ๋กœ ์ง์ ‘ ์ ‘๊ทผํ•ด๋„ ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. ๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 7972b2a commit 1685d3b

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

โ€Ž.github/workflows/deploy.ymlโ€Ž

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,67 @@ jobs:
4242
- name: Build
4343
run: pnpm run build
4444

45+
- name: Create 404.html for SPA routing
46+
run: |
47+
cat > ./build/client/404.html << 'EOF'
48+
<!DOCTYPE html>
49+
<html>
50+
<head>
51+
<meta charset="utf-8">
52+
<title>Single Page Apps for GitHub Pages</title>
53+
<script type="text/javascript">
54+
// Single Page Apps for GitHub Pages
55+
// MIT License
56+
// https://github.com/rafgraph/spa-github-pages
57+
// This script takes the current url and converts the path and query
58+
// string into just a query string, and then redirects the browser
59+
// to the new url with only a query string and hash fragment,
60+
// e.g. https://www.foo.tld/one/two?a=b&c=d#qwe, becomes
61+
// https://www.foo.tld/?/one/two&a=b~and~c=d#qwe
62+
// Note: this 404.html file must be at least 512 bytes for it to work
63+
// with Internet Explorer (it is currently > 512 bytes)
64+
65+
// If you're creating a Project Pages site and NOT using a custom domain,
66+
// then set pathSegmentsToKeep to 1 (enterprise users may need to set it to > 1).
67+
// This way the code will only replace the route part of the path, and not
68+
// the real directory in which the app resides, for example:
69+
// https://username.github.io/repo-name/one/two?a=b&c=d#qwe becomes
70+
// https://username.github.io/repo-name/?/one/two&a=b~and~c=d#qwe
71+
// Otherwise, leave pathSegmentsToKeep as 0.
72+
var pathSegmentsToKeep = 1;
73+
74+
var l = window.location;
75+
l.replace(
76+
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
77+
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
78+
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
79+
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
80+
l.hash
81+
);
82+
</script>
83+
</head>
84+
<body>
85+
</body>
86+
</html>
87+
EOF
88+
89+
- name: Add redirect script to index.html
90+
run: |
91+
# index.html์˜ <head> ํƒœ๊ทธ ์งํ›„์— ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ์Šคํฌ๋ฆฝํŠธ ์‚ฝ์ž…
92+
sed -i '/<head>/a\
93+
<script type="text/javascript">\
94+
(function(l) {\
95+
if (l.search[1] === '/' ) {\
96+
var decoded = l.search.slice(1).split('\''&'\'').map(function(s) { \
97+
return s.replace(/~and~/g, '\''&'\'')\
98+
}).join('\''?'\'');\
99+
window.history.replaceState(null, null,\
100+
l.pathname.slice(0, -1) + decoded + l.hash\
101+
);\
102+
}\
103+
}(window.location))\
104+
</script>' ./build/client/index.html
105+
45106
- name: Upload artifact
46107
uses: actions/upload-pages-artifact@v3
47108
with:

0 commit comments

Comments
ย (0)