Skip to content

Commit 04d2839

Browse files
cleanup workflows
Signed-off-by: saurabhraghuvanshii <saurabhsraghuvanshi@gmail.com>
1 parent 17492bc commit 04d2839

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

.github/workflows/build-and-deploy-site.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,28 @@ jobs:
4242
# User/organization sites use a repo named <owner>.github.io and are served from the domain root.
4343
- name: Build site
4444
env:
45-
GITHUB_PAGES_ORIGIN: ${{ vars.GITHUB_PAGES_ORIGIN }}
45+
PUBLIC_SITE_URL: ${{ vars.PUBLIC_SITE_URL }}
4646
run: |
4747
owner="${GITHUB_REPOSITORY%%/*}"
4848
repo_name="${GITHUB_REPOSITORY#*/}"
49-
pages_origin="${GITHUB_PAGES_ORIGIN:-https://${owner}.github.io}"
50-
pages_origin="${pages_origin%/}"
5149
52-
if [[ "$repo_name" == "${owner}.github.io" ]]; then
53-
export GATSBY_SITE_URL="$pages_origin"
50+
# Simple rule:
51+
# - If PUBLIC_SITE_URL is set (custom domain), build at root (no repo prefix).
52+
# - Otherwise use GitHub Pages URL; project repos need pathPrefix=<repo>.
53+
if [[ -n "${PUBLIC_SITE_URL:-}" ]]; then
54+
export GATSBY_SITE_URL="${PUBLIC_SITE_URL%/}"
55+
unset PATH_PREFIX
5456
npm run build
5557
else
56-
export GATSBY_SITE_URL="$pages_origin"
57-
export PATH_PREFIX="$repo_name"
58-
npm run build:gh-pages
58+
if [[ "$repo_name" == "${owner}.github.io" ]]; then
59+
export GATSBY_SITE_URL="https://${owner}.github.io"
60+
unset PATH_PREFIX
61+
npm run build
62+
else
63+
export GATSBY_SITE_URL="https://${owner}.github.io"
64+
export PATH_PREFIX="$repo_name"
65+
npm run build:gh-pages
66+
fi
5967
fi
6068
touch public/.nojekyll
6169

.github/workflows/build-and-preview-site.yml

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ jobs:
2424
ref: ${{ github.event.pull_request.head.sha }}
2525
fetch-depth: 0
2626

27-
- name: Checkout for cleanup
27+
- name: Checkout base branch for cleanup
2828
if: github.event.action == 'closed'
2929
uses: actions/checkout@v6
3030
with:
31-
ref: gh-pages
32-
fetch-depth: 0
31+
ref: ${{ github.event.pull_request.base.ref }}
32+
fetch-depth: 1
3333

3434
- name: Setup Node
3535
if: github.event.action != 'closed'
@@ -41,33 +41,24 @@ jobs:
4141
if: github.event.action != 'closed'
4242
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
4343

44-
# Project Pages URLs are https://<owner>.github.io/<repo>/… so Gatsby pathPrefix must
45-
# include <repo> (e.g. layer5/pr-preview/pr-9), not only /pr-preview/pr-9 — otherwise JS/CSS
46-
# load from the wrong path and the shell renders without client-side content.
4744
- name: Resolve preview URLs
4845
if: github.event.action != 'closed'
4946
id: preview-vars
5047
env:
5148
PREVIEW_SITE_URL: ${{ vars.PREVIEW_SITE_URL }}
52-
GITHUB_PAGES_ORIGIN: ${{ vars.GITHUB_PAGES_ORIGIN }}
49+
PUBLIC_SITE_URL: ${{ vars.PUBLIC_SITE_URL }}
5350
run: |
5451
owner="${GITHUB_REPOSITORY%%/*}"
5552
repo_name="${GITHUB_REPOSITORY#*/}"
5653
pr="pr-${{ github.event.pull_request.number }}"
54+
base="${PREVIEW_SITE_URL:-${PUBLIC_SITE_URL:-}}"
5755
58-
if [[ -n "${PREVIEW_SITE_URL:-}" ]]; then
59-
base="${PREVIEW_SITE_URL%/}"
60-
pages_origin="$(printf '%s' "$base" | sed -E 's|(https?://[^/]+).*|\1|')"
61-
repo_path="$(printf '%s' "$base" | sed -E 's|https?://[^/]+||' | sed 's|^/||;s|/$||')"
62-
if [[ -n "$repo_path" ]]; then
63-
path_prefix="${repo_path}/pr-preview/${pr}"
64-
else
65-
path_prefix="pr-preview/${pr}"
66-
fi
67-
preview_url="${base}/pr-preview/${pr}/"
56+
if [[ -n "$base" ]]; then
57+
pages_origin="${base%/}"
58+
path_prefix="pr-preview/${pr}"
59+
preview_url="${pages_origin}/pr-preview/${pr}/"
6860
else
69-
pages_origin="${GITHUB_PAGES_ORIGIN:-https://${owner}.github.io}"
70-
pages_origin="${pages_origin%/}"
61+
pages_origin="https://${owner}.github.io"
7162
if [[ "$repo_name" == "${owner}.github.io" ]]; then
7263
path_prefix="pr-preview/${pr}"
7364
preview_url="${pages_origin}/pr-preview/${pr}/"

src/components/seo.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33
import { useLocation } from "@reach/router";
4-
import { useStaticQuery, graphql, withPrefix } from "gatsby";
4+
import { useStaticQuery, graphql } from "gatsby";
55
import FavIcon from "../assets/images/favicon.webp";
66

77
export const useSiteMetadata = () => {
@@ -43,9 +43,7 @@ const SEO = ({
4343
const toAbsoluteUrl = (value) => {
4444
if (!value) return value;
4545
if (/^(?:[a-z]+:)?\/\//i.test(value)) return value;
46-
47-
const resolvedPath = withPrefix(value).replace(/^\//, "");
48-
return new URL(resolvedPath, `${siteUrl}/`).toString();
46+
return new URL(value.replace(/^\//, ""), `${siteUrl}/`).toString();
4947
};
5048
const seo = {
5149
title: title || defaultTitle,

0 commit comments

Comments
 (0)