diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f3c2537..ccdc7ac 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -38,11 +38,17 @@ jobs: run: npm run test - name: Build application - run: npm run build + run: | + echo "Building for branch: ${{ github.ref_name }}" + echo "NODE_ENV: $NODE_ENV" + echo "SURGE_PREVIEW: $SURGE_PREVIEW" + npm run build env: NEXT_PUBLIC_GA_ID: ${{ secrets.NEXT_PUBLIC_GA_ID }} NEXT_PUBLIC_REQUIRE_CONSENT: true NEXT_PUBLIC_ANONYMIZE_IP: true + # Set SURGE_PREVIEW for non-master branches to disable basePath + SURGE_PREVIEW: ${{ github.ref != 'refs/heads/master' && 'true' || '' }} - name: Upload Pages Artifact (Production) if: github.ref == 'refs/heads/master' diff --git a/next.config.ts b/next.config.ts index 55c8586..7efaba3 100644 --- a/next.config.ts +++ b/next.config.ts @@ -4,8 +4,11 @@ const nextConfig: NextConfig = { // Output as static site for GitHub Pages output: 'export', - // Base path for GitHub Pages (only in production) - basePath: process.env.NODE_ENV === 'production' ? '/github-profile-readme-generator' : '', + // Base path for GitHub Pages (only in production AND not for Surge previews) + basePath: + process.env.NODE_ENV === 'production' && !process.env.SURGE_PREVIEW + ? '/github-profile-readme-generator' + : '', // Image optimization for static export images: {