From 8e2ffc5e0d9f079a25c6be7c006d40ccd869b402 Mon Sep 17 00:00:00 2001 From: Sheraff Date: Sun, 2 Jun 2024 12:08:48 +0200 Subject: [PATCH] chore: Add deployment workflow for GitHub Pages and update base URL in app --- .github/workflows/deploy.yml | 66 ++++++++++++++++++++++++++++++++++++ src/App.tsx | 2 +- src/Navigation.tsx | 7 ++-- vite.config.ts | 1 + 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..84b2c46 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/src/App.tsx b/src/App.tsx index 4339561..a0f0fac 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -17,7 +17,7 @@ function App() {
{Object.entries(ROUTES).map(([route, { meta }]) => (
-

{meta.title}

+

{meta.title}


))} diff --git a/src/Navigation.tsx b/src/Navigation.tsx index 2218007..c5442de 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -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 } @@ -61,6 +62,6 @@ export function useNavigation() { return useContext(NavigationContext) } -export function Link(props: Omit, "href"> & { href: `/${Routes}` | '/' }) { - return +export function Link({ href, ...props }: Omit, "href"> & { href: `/${Routes}` | '/' }) { + return } \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index e90d897..f882e12 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -9,5 +9,6 @@ export default defineConfig(async () => { return ({ plugins: [react(), fileRouter(), viteTsconfigPaths()], clearScreen: false, + base: '/vite-labs/' }) })