File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed
Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change 5151 # - If PUBLIC_SITE_URL is set (custom domain), build at root (no repo prefix).
5252 # - Otherwise use GitHub Pages URL; project repos need pathPrefix=<repo>.
5353 if [[ -n "${PUBLIC_SITE_URL:-}" ]]; then
54- export GATSBY_SITE_URL="${PUBLIC_SITE_URL%/}"
55- unset PATH_PREFIX
56- npm run build
54+ base="${PUBLIC_SITE_URL%/}"
55+ site_origin="$(printf '%s' "$base" | sed -E 's|(https?://[^/]+).*|\1|')"
56+ site_path="$(printf '%s' "$base" | sed -E 's|https?://[^/]+||' | sed 's|^/||;s|/$||')"
57+ site_host="$(printf '%s' "$site_origin" | sed -E 's|https?://||')"
58+
59+ export GATSBY_SITE_URL="$site_origin"
60+ if [[ -n "$site_path" ]]; then
61+ export PATH_PREFIX="$site_path"
62+ npm run build:gh-pages
63+ else
64+ unset PATH_PREFIX
65+ npm run build
66+ fi
5767 else
5868 if [[ "$repo_name" == "${owner}.github.io" ]]; then
5969 export GATSBY_SITE_URL="https://${owner}.github.io"
6777 fi
6878 touch public/.nojekyll
6979
80+ # Preserve custom domain in GitHub Pages settings by committing CNAME.
81+ if [[ -n "${site_host:-}" ]]; then
82+ printf '%s\n' "$site_host" > public/CNAME
83+ fi
84+
7085 - name : Deploy to GitHub Pages
7186 uses : peaceiris/actions-gh-pages@v4
7287 with :
Original file line number Diff line number Diff line change 5454 base="${PREVIEW_SITE_URL:-${PUBLIC_SITE_URL:-}}"
5555
5656 if [[ -n "$base" ]]; then
57- pages_origin="${base%/}"
58- path_prefix="pr-preview/${pr}"
59- preview_url="${pages_origin}/pr-preview/${pr}/"
57+ base="${base%/}"
58+ pages_origin="$(printf '%s' "$base" | sed -E 's|(https?://[^/]+).*|\1|')"
59+ base_path="$(printf '%s' "$base" | sed -E 's|https?://[^/]+||' | sed 's|^/||;s|/$||')"
60+ if [[ -n "$base_path" ]]; then
61+ path_prefix="${base_path}/pr-preview/${pr}"
62+ preview_url="${pages_origin}/${base_path}/pr-preview/${pr}/"
63+ else
64+ path_prefix="pr-preview/${pr}"
65+ preview_url="${pages_origin}/pr-preview/${pr}/"
66+ fi
6067 else
6168 pages_origin="https://${owner}.github.io"
6269 if [[ "$repo_name" == "${owner}.github.io" ]]; then
You can’t perform that action at this time.
0 commit comments