Skip to content

Commit 7f671b4

Browse files
fix build site baseurl
Signed-off-by: saurabhraghuvanshii <saurabhsraghuvanshi@gmail.com>
1 parent 910ebac commit 7f671b4

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

.github/workflows/build-and-deploy-site.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,26 @@ jobs:
3737
- name: Install dependencies
3838
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
3939

40+
# GitHub project pages are served from https://<owner>.github.io/<repo>/.
41+
# Gatsby must use pathPrefix + `gatsby build --prefix-paths` or scripts/CSS load from / and break.
42+
# User/organization sites use a repo named <owner>.github.io and are served from the domain root.
4043
- name: Build site
44+
env:
45+
GITHUB_PAGES_ORIGIN: ${{ vars.GITHUB_PAGES_ORIGIN }}
4146
run: |
42-
npm run build
47+
owner="${GITHUB_REPOSITORY%%/*}"
48+
repo_name="${GITHUB_REPOSITORY#*/}"
49+
pages_origin="${GITHUB_PAGES_ORIGIN:-https://${owner}.github.io}"
50+
pages_origin="${pages_origin%/}"
51+
52+
if [[ "$repo_name" == "${owner}.github.io" ]]; then
53+
export GATSBY_SITE_URL="$pages_origin"
54+
npm run build
55+
else
56+
export GATSBY_SITE_URL="$pages_origin"
57+
export PATH_PREFIX="$repo_name"
58+
npm run build:gh-pages
59+
fi
4360
touch public/.nojekyll
4461
4562
- name: Deploy to GitHub Pages

gatsby-config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ module.exports = {
4545
"Expect more from your infrastructure. Cloud native, open source software for your internal development platforms, your DevOps, platform engineering and site reliability engineering teams. Less finger-pointing and more collaborating. Allowing developers to focus on business logic, not infrastructure concerns. Empowering operators to confidently run modern infrastructure.",
4646
author: "Layer5 Authors",
4747
permalink: siteRootUrl,
48-
siteUrl: siteOrigin,
48+
// Use the full public root (origin + pathPrefix) so GitHub Pages project sites,
49+
// PR previews, and feeds resolve URLs under the correct base path.
50+
siteUrl: siteRootUrl,
4951
image: "/images/layer5-gradient.webp",
5052
twitterUsername: "@layer5",
5153
},

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"scripts": {
1313
"build": "cross-env BUILD_FULL_SITE=true NODE_OPTIONS=--max-old-space-size=8192 gatsby build",
14+
"build:gh-pages": "cross-env BUILD_FULL_SITE=true NODE_OPTIONS=--max-old-space-size=8192 gatsby build --prefix-paths",
1415
"build:preview": "cross-env BUILD_FULL_SITE=true GATSBY_PREVIEW=true NODE_OPTIONS=--max-old-space-size=8192 gatsby build --prefix-paths",
1516
"clean": "gatsby clean",
1617
"clean:all": "gatsby clean && rimraf node_modules",

0 commit comments

Comments
 (0)