Skip to content

Commit

Permalink
chore: Add deployment workflow for GitHub Pages and update base URL i…
Browse files Browse the repository at this point in the history
…n app
  • Loading branch information
Sheraff committed Jun 2, 2024
1 parent 5072b67 commit 8e2ffc5
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm i --frozen-lockfile
- name: Build
run: pnpm build
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload dist folder
path: "./dist"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function App() {
<hr />
{Object.entries(ROUTES).map(([route, { meta }]) => (
<div key={route}>
<a href={`/${route}`}><h2>{meta.title}</h2></a>
<a href={`${import.meta.env.BASE_URL}${route}`}><h2>{meta.title}</h2></a>
<hr />
</div>
))}
Expand Down
7 changes: 4 additions & 3 deletions src/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ declare global {

function parseUrl(href: string) {
const url = new URL(href)
const key = url.pathname.slice(1)
if (!url.pathname.startsWith(import.meta.env.BASE_URL)) return null
const key = url.pathname.slice(import.meta.env.BASE_URL.length)
if (key in ROUTES) {
return key as Routes
}
Expand Down Expand Up @@ -61,6 +62,6 @@ export function useNavigation() {
return useContext(NavigationContext)
}

export function Link(props: Omit<ComponentPropsWithoutRef<"a">, "href"> & { href: `/${Routes}` | '/' }) {
return <a {...props} />
export function Link({ href, ...props }: Omit<ComponentPropsWithoutRef<"a">, "href"> & { href: `/${Routes}` | '/' }) {
return <a {...props} href={import.meta.env.BASE_URL + href.slice(1)} />
}
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export default defineConfig(async () => {
return ({
plugins: [react(), fileRouter(), viteTsconfigPaths()],
clearScreen: false,
base: '/vite-labs/'
})
})

0 comments on commit 8e2ffc5

Please sign in to comment.