|
42 | 42 | - name: Build |
43 | 43 | run: pnpm run build |
44 | 44 |
|
| 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 | +
|
45 | 106 | - name: Upload artifact |
46 | 107 | uses: actions/upload-pages-artifact@v3 |
47 | 108 | with: |
|
0 commit comments