Skip to content

Commit 08a8055

Browse files
monapdxcursoragent
andcommitted
Fix Pages base for user.github.io repos; pass GITHUB_REPOSITORY in CI
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent d8b26e3 commit 08a8055

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

.github/workflows/deploy-pages.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
cache: npm
2626
- run: npm ci
2727
- run: npm run build
28+
env:
29+
# Ensure Vite sees the repo id (project Pages need /<repo>/ base).
30+
GITHUB_REPOSITORY: ${{ github.repository }}
2831
# No configure-pages: it calls the Pages API and 404s until Settings → Pages
2932
# uses "GitHub Actions". Static Vite output does not need that action anyway.
3033
- uses: actions/upload-pages-artifact@v3

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ This repo includes a workflow that builds with Vite and publishes the `dist` fol
2626

2727
To rebuild manually, use **Actions → Deploy to GitHub Pages → Run workflow**.
2828

29+
### Site looks blank (white page)
30+
31+
1. **Project site URL** — For a normal repo named `zine-maker`, the app lives at `https://<user>.github.io/zine-maker/` (with the repo slug in the path). Opening only `https://<user>.github.io/` will not load this app.
32+
2. **User/org Pages repo** — If the repo is named `<user>.github.io` or `<org>.github.io`, the site is served from the domain root (`/`). The build sets Vite `base` to `/` automatically in that case.
33+
3. In the browser, open DevTools → **Network**, reload, and check whether `*.js` / `*.css` return **404**. Wrong `base` usually shows every asset as 404.
34+
2935
### Custom base path (optional)
3036

3137
Override the asset prefix when building:

vite.config.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import { defineConfig } from 'vite'
22
import react from '@vitejs/plugin-react'
33

4-
// GitHub Pages project sites are served from /<repo>/; Actions sets GITHUB_REPOSITORY=owner/repo.
5-
const repo = process.env.GITHUB_REPOSITORY?.split('/')[1]
6-
const base =
7-
process.env.VITE_BASE_PATH ?? (repo ? `/${repo}/` : '/')
4+
// GitHub Pages: project sites use /<repo>/; user/org sites use the special <owner>.github.io repo at /.
5+
function resolveBase(): string {
6+
if (process.env.VITE_BASE_PATH) return process.env.VITE_BASE_PATH
7+
const full = process.env.GITHUB_REPOSITORY
8+
if (!full?.includes('/')) return '/'
9+
const [owner, repo] = full.split('/')
10+
if (
11+
owner &&
12+
repo &&
13+
repo.toLowerCase() === `${owner.toLowerCase()}.github.io`
14+
) {
15+
return '/'
16+
}
17+
return `/${repo}/`
18+
}
19+
20+
const base = resolveBase()
821

922
// https://vite.dev/config/
1023
export default defineConfig({

0 commit comments

Comments
 (0)