Skip to content

Fix rspress base path for GitHub Pages sub-path deployment#73

Merged
JRS1986 merged 1 commit into
mainfrom
fix/rspress-base-path
May 19, 2026
Merged

Fix rspress base path for GitHub Pages sub-path deployment#73
JRS1986 merged 1 commit into
mainfrom
fix/rspress-base-path

Conversation

@JRS1986
Copy link
Copy Markdown
Owner

@JRS1986 JRS1986 commented May 19, 2026

The bug

The deployed docs site rendered as raw HTML — no CSS, giant unstyled GitHub SVG taking over the page. Classic "CSS didn't load" symptoms.

Cause: GitHub Pages serves this project site at `https://jrs1986.github.io/CodingScaffold/\` (a sub-path under the account-level apex). rspress was emitting asset URLs at the apex:

```
href="/static/css/styles.a229748ab8.css" # resolves to https://jrs1986.github.io/static/... ← 404
```

Confirmed by `curl -s https://jrs1986.github.io/CodingScaffold/ | grep href` against the deployed HTML.

The fix

One line in `docs/rspress.config.ts`:

```ts
base: '/CodingScaffold/',
```

After this, the generator prefixes every emitted `href`/`src`:

```
href="/CodingScaffold/static/css/styles.a229748ab8.css" ← resolves correctly
```

Verification

Local build inspects:

```
$ cd docs && npm ci && npm run build
$ grep -oE 'href="[^\"]\.css"|src="[^\"]\.js"' doc_build/index.html | head -3
href="/CodingScaffold/static/css/styles.a229748ab8.css"
src="/CodingScaffold/static/js/styles.817d7b47ee.js"
src="/CodingScaffold/static/js/lib-react.dd63507a08.js"
```

Trailing slash on `base` matters — rspress normalizes URLs against it.

After merge, the next push to `main` triggers `docs.yml`, which redeploys with the corrected base path. The site at https://jrs1986.github.io/CodingScaffold/ should style up immediately.

Local dev still works

`npm run dev` at `127.0.0.1:3000` still serves at the root (rspress strips `base` for the local dev server), so no change for local writers.

GitHub Pages serves this project at https://jrs1986.github.io/CodingScaffold/,
a sub-path. rspress was emitting asset URLs at the apex (e.g.
/static/css/styles.css) which resolved to jrs1986.github.io/static/...
and 404'd — leaving the deployed site rendered as unstyled HTML with
a giant raw GitHub SVG.

Setting base: '/CodingScaffold/' in rspress.config.ts makes the
generator prefix every emitted href/src so assets resolve at the right
URL. Verified locally: doc_build/index.html now references
/CodingScaffold/static/css/... etc.

Trailing slash matters — rspress normalizes URLs against it. The
local `npm run dev` server still works because rspress strips base
when serving from 127.0.0.1.
@JRS1986 JRS1986 merged commit ef58482 into main May 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant