Skip to content

Commit bcc9e41

Browse files
authored
add support for github pages
1 parent df031b3 commit bcc9e41

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

.github/workflows/static.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

src/BrowserApp.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import { BrowserRouter } from 'react-router-dom';
33
import { SchemaApp } from './SchemaApp'
4+
import { getBasename } from './basename'
45

56
export const App: React.FC = () => (
6-
<BrowserRouter>
7+
<BrowserRouter basename={getBasename() !== "" ? getBasename() : undefined}>
78
<SchemaApp />
89
</BrowserRouter>
910
)

src/basename.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const getBasename = () => {
2+
const pathname = new URL(document.baseURI).pathname;
3+
return pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
4+
}

webpack.common.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = {
3535
new HtmlWebpackPlugin({
3636
title: 'JSON Schema Viewer',
3737
template: 'index.html',
38-
publicPath: '/',
38+
publicPath: process.env.WEBPACK_PUBLIC_PATH ?? '/',
3939
filename: 'index.html'
4040
}),
4141
new CspHtmlWebpackPlugin({
@@ -51,7 +51,7 @@ module.exports = {
5151
}),
5252
new FaviconsWebpackPlugin({
5353
logo: './src/logo.svg',
54-
publicPath: '/',
54+
publicPath: process.env.WEBPACK_PUBLIC_PATH ?? '/',
5555
prefix: 'auto/[contenthash]'
5656
})
5757
]

0 commit comments

Comments
 (0)