diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 818a9fd..3153d32 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -53,7 +53,7 @@ jobs: npm run build if [ -f CNAME ] && [ "${{ github.repository_owner }}" = "mume" ]; then cp CNAME dist/CNAME; fi env: - VITE_BASE: ${{ steps.pages.outputs.base_path }}/ + VITE_BASE: ${{ env.VITE_BASE || format('{0}/', steps.pages.outputs.base_path) }} - name: Collect PRs to deploy uses: actions/github-script@v9 diff --git a/scripts/ci-env.sh b/scripts/ci-env.sh index c280ee9..55e9544 100755 --- a/scripts/ci-env.sh +++ b/scripts/ci-env.sh @@ -4,18 +4,20 @@ export VITE_LAST_UPDATED=$(git log -1 --format=%cd --date=format:'%B %Y') echo "VITE_LAST_UPDATED=$VITE_LAST_UPDATED" >> $GITHUB_ENV +OWNER="${GITHUB_REPOSITORY_OWNER:-mume}" +REPO=$(echo "${GITHUB_REPOSITORY:-${OWNER}/mume.github.io}" | cut -d'/' -f2) + # Set VITE_HOSTNAME from CNAME file if it exists -if [ -f CNAME ] && [ "$GITHUB_REPOSITORY_OWNER" = "mume" ]; then - export VITE_HOSTNAME="https://$(cat CNAME)" +if [ -f CNAME ] && [ "$OWNER" = "mume" ]; then + CNAME_VAL=$(tr -d '[:space:]' < CNAME) + export VITE_HOSTNAME="https://$CNAME_VAL" else # Fallback for PR previews if host/prefix are provided via env if [ -n "$PREVIEW_HOST" ]; then export VITE_HOSTNAME="https://${PREVIEW_HOST}${PREVIEW_PREFIX}" else # Fallback for forks or main repo without CNAME - OWNER="${GITHUB_REPOSITORY_OWNER:-mume}" - REPO=$(echo "${GITHUB_REPOSITORY:-${OWNER}/docs}" | cut -d'/' -f2) - if [ "$OWNER" = "mume" ] && [ "$REPO" = "docs" ]; then + if [ "$OWNER" = "mume" ] && [ "$REPO" = "mume.github.io" ]; then export VITE_HOSTNAME="https://docs.mume.org" elif [ "$REPO" = "$OWNER.github.io" ]; then export VITE_HOSTNAME="https://$OWNER.github.io" @@ -25,3 +27,9 @@ else fi fi echo "VITE_HOSTNAME=$VITE_HOSTNAME" >> $GITHUB_ENV + +# Explicitly set VITE_BASE=/ for the official production environment +if [ "$OWNER" = "mume" ] && [ "$REPO" = "mume.github.io" ]; then + export VITE_BASE="/" + echo "VITE_BASE=$VITE_BASE" >> $GITHUB_ENV +fi