Skip to content

Commit 7055b39

Browse files
committed
fix: remove repo name from basePath when using custom domain
Custom domain (dev.codebuilder.org) doesn't include the repo name in the URL path, so basePath should be /preview/<branch> not /codebuilder-frontend/preview/<branch>
1 parent 88f6cac commit 7055b39

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

.github/workflows/nextjs-static-gh-pages.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ jobs:
2828
id: vars
2929
run: |
3030
REPO_NAME="${{ github.event.repository.name }}"
31+
# Custom domain means no repo name prefix in the URL path.
32+
# Set CUSTOM_DOMAIN to your domain, or leave empty to use github.io/<repo> URLs.
33+
CUSTOM_DOMAIN="dev.codebuilder.org"
3134
3235
# Get the branch name (works for both push and PR events)
3336
if [ "${{ github.event_name }}" = "pull_request" ]; then
@@ -39,16 +42,26 @@ jobs:
3942
# Sanitize branch name for use in URL paths
4043
SAFE_BRANCH=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9._-]/-/g')
4144
45+
if [ -n "$CUSTOM_DOMAIN" ]; then
46+
BASE_URL="https://${CUSTOM_DOMAIN}"
47+
else
48+
BASE_URL="https://${{ github.repository_owner }}.github.io/${REPO_NAME}"
49+
fi
50+
4251
if [ "$BRANCH" = "main" ]; then
43-
echo "base_path=/${REPO_NAME}" >> $GITHUB_OUTPUT
52+
if [ -n "$CUSTOM_DOMAIN" ]; then
53+
echo "base_path=" >> $GITHUB_OUTPUT
54+
else
55+
echo "base_path=/${REPO_NAME}" >> $GITHUB_OUTPUT
56+
fi
4457
echo "dest_dir=" >> $GITHUB_OUTPUT
4558
echo "keep_files=false" >> $GITHUB_OUTPUT
46-
echo "preview_url=https://${{ github.repository_owner }}.github.io/${REPO_NAME}/" >> $GITHUB_OUTPUT
59+
echo "preview_url=${BASE_URL}/" >> $GITHUB_OUTPUT
4760
else
48-
echo "base_path=/${REPO_NAME}/preview/${SAFE_BRANCH}" >> $GITHUB_OUTPUT
61+
echo "base_path=/preview/${SAFE_BRANCH}" >> $GITHUB_OUTPUT
4962
echo "dest_dir=preview/${SAFE_BRANCH}" >> $GITHUB_OUTPUT
5063
echo "keep_files=true" >> $GITHUB_OUTPUT
51-
echo "preview_url=https://${{ github.repository_owner }}.github.io/${REPO_NAME}/preview/${SAFE_BRANCH}/" >> $GITHUB_OUTPUT
64+
echo "preview_url=${BASE_URL}/preview/${SAFE_BRANCH}/" >> $GITHUB_OUTPUT
5265
fi
5366
5467
echo "branch=$BRANCH" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)