diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index d0aba7ecc6..0eb5d6b42e 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -35,12 +35,45 @@ jobs: echo "should-run=true" >> $GITHUB_OUTPUT fi + # Notify fork PRs that preview is not available + fork-notice: + needs: check-draft + if: | + needs.check-draft.outputs.should-run == 'true' && + github.event.action != 'closed' && + github.event.pull_request.head.repo.full_name != github.repository + runs-on: ubuntu-latest + steps: + - name: Post fork notice comment + uses: actions/github-script@v7 + with: + script: | + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + + const marker = ''; + const existing = comments.find(c => c.body.includes(marker)); + + if (!existing) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: `${marker}\n## 📝 PR Preview Not Available\n\nPR previews are not available for pull requests from forks due to GitHub Actions security restrictions.\n\nTo preview your changes locally, run:\n\`\`\`bash\nnpx hugo server\n\`\`\`\n\nOnce merged, your changes will be visible on the production site.` + }); + } + # Build and deploy preview preview: needs: check-draft + # Skip fork PRs - GITHUB_TOKEN doesn't have write access to push to gh-pages if: | needs.check-draft.outputs.should-run == 'true' && - github.event.action != 'closed' + github.event.action != 'closed' && + github.event.pull_request.head.repo.full_name == github.repository runs-on: ubuntu-latest steps: - name: Checkout diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 0dd150396b..85caa0d2f2 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -1,8 +1,10 @@ {{ $currentPage := . }} {{ $productPathData := findRE "[^/]+.*?" .RelPermalink }} -{{ $product := index $productPathData 0 }} +{{/* Support deployments (such as CI tools) with subdirectory baseURL */}} +{{ $pathOffset := .Site.Params.prPreviewPathOffset | default 0 }} +{{ $product := index $productPathData (add $pathOffset 0) }} {{ $productName := (index .Site.Data.products $product).name }} -{{ $currentVersion := index $productPathData 1 }} +{{ $currentVersion := index $productPathData (add $pathOffset 1) }} {{ .Scratch.Set "menuKey" "menu"}} diff --git a/layouts/shortcodes/product-name.html b/layouts/shortcodes/product-name.html index 355ea5c25e..d71e5bea6f 100644 --- a/layouts/shortcodes/product-name.html +++ b/layouts/shortcodes/product-name.html @@ -1,5 +1,7 @@ {{- $productPathData := findRE "[^/]+.*?" .Page.RelPermalink -}} -{{- $currentProduct := index $productPathData 1 -}} +{{- /* Support deployments (such as CI tools) with subdirectory baseURL */ -}} +{{- $pathOffset := .Site.Params.prPreviewPathOffset | default 0 -}} +{{- $currentProduct := index $productPathData (add $pathOffset 1) -}} {{- $length := .Get 0 | default "long" -}} {{- $omit := .Get "omit" | default "" -}} {{- $scratch := newScratch -}}