File tree 4 files changed +69
-3
lines changed
4 files changed +69
-3
lines changed Original file line number Diff line number Diff line change
1
+ # Simple workflow for deploying static content to GitHub Pages
2
+ name : Deploy static content to Pages
3
+
4
+ on :
5
+ # Runs on pushes targeting the default branch
6
+ push :
7
+ branches : ["master"]
8
+
9
+ # Allows you to run this workflow manually from the Actions tab
10
+ workflow_dispatch :
11
+
12
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13
+ permissions :
14
+ contents : read
15
+ pages : write
16
+ id-token : write
17
+
18
+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19
+ # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20
+ concurrency :
21
+ group : " pages"
22
+ cancel-in-progress : false
23
+
24
+ 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 }}
30
+ runs-on : ubuntu-latest
31
+ steps :
32
+ - name : Checkout
33
+ uses : actions/checkout@v4
34
+
35
+ - name : Setup Pages
36
+ uses : actions/configure-pages@v5
37
+
38
+ - name : Use Node.js 16
39
+ uses : actions/setup-node@v3
40
+ with :
41
+ node-version : 16
42
+ cache : ' yarn'
43
+
44
+ - id : env
45
+ run : echo "repo-name=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_OUTPUT
46
+
47
+ - run : yarn install --frozen-lockfile
48
+ - run : yarn lint
49
+ - run : yarn test
50
+ - run : yarn build-prod
51
+ env :
52
+ WEBPACK_PUBLIC_PATH : " /${{ steps.env.outputs.repo-name }}"
53
+
54
+ - name : Upload artifact
55
+ uses : actions/upload-pages-artifact@v3
56
+ with :
57
+ path : ' dist/'
58
+
59
+ - name : Deploy to GitHub Pages
60
+ id : deployment
61
+ uses : actions/deploy-pages@v4
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import { BrowserRouter } from 'react-router-dom' ;
3
3
import { SchemaApp } from './SchemaApp'
4
+ import { getBasename } from './basename'
4
5
5
6
export const App : React . FC = ( ) => (
6
- < BrowserRouter >
7
+ < BrowserRouter basename = { getBasename ( ) !== "" ? getBasename ( ) : undefined } >
7
8
< SchemaApp />
8
9
</ BrowserRouter >
9
10
)
Original file line number Diff line number Diff line change
1
+ export const getBasename = ( ) => {
2
+ const pathname = new URL ( document . baseURI ) . pathname ;
3
+ return pathname . endsWith ( "/" ) ? pathname . slice ( 0 , - 1 ) : pathname ;
4
+ }
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ module.exports = {
35
35
new HtmlWebpackPlugin ( {
36
36
title : 'JSON Schema Viewer' ,
37
37
template : 'index.html' ,
38
- publicPath : '/' ,
38
+ publicPath : process . env . WEBPACK_PUBLIC_PATH ?? '/' ,
39
39
filename : 'index.html'
40
40
} ) ,
41
41
new CspHtmlWebpackPlugin ( {
@@ -51,7 +51,7 @@ module.exports = {
51
51
} ) ,
52
52
new FaviconsWebpackPlugin ( {
53
53
logo : './src/logo.svg' ,
54
- publicPath : '/' ,
54
+ publicPath : process . env . WEBPACK_PUBLIC_PATH ?? '/' ,
55
55
prefix : 'auto/[contenthash]'
56
56
} )
57
57
]
You can’t perform that action at this time.
0 commit comments