From f4dc0d16b529870bd3794c6444268abb0a998dc1 Mon Sep 17 00:00:00 2001 From: Matt Linville Date: Fri, 25 Apr 2025 15:35:18 -0700 Subject: [PATCH] Update production script - Improve the check for whether we are in Cloudflare - Determine if we are building main or a PR preview - Echo the Cloudflare variables for debugging - Only set a specific Hugo build context if we are in a PR preview - Improve how the sitemap is moved around - More code comments --- scripts/production.sh | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/scripts/production.sh b/scripts/production.sh index 24daae2e6..1dee60377 100644 --- a/scripts/production.sh +++ b/scripts/production.sh @@ -1,17 +1,36 @@ # Run this from root by calling sh ./scripts/production.sh # Build the English docs from this branch + +# Update Hugo if necessary hugo mod get -u +# Clear out previous build artifacts rm -rf public -if [ -n "$CF_PAGES_URL" ]; then - echo "Building in Cloudflare" - hugo -b $CF_PAGES_URL + +# Detect whether we are in Cloudflare +if [ -n "$CF_PAGES" ] && [ -n "$CF_PAGES_URL" ]; then + echo "Building in Cloudflare with these variables:" + echo " CF_PAGES: $CF_PAGES" + echo " CF_PAGES_URL: $CF_PAGES_URL" + echo " CF_PAGES_COMMIT_SHA: $CF_PAGES_COMMIT_SHA" + echo " CF_PAGES_BRANCH: $CF_PAGES_BRANCH" + if [ "$CF_PAGES_BRANCH" = "main" ]; then + echo "Building the main site" + hugo + else + echo "Building a PR preview" + hugo -b $CF_PAGES_URL + fi else echo "Building locally" hugo fi + +# Move English sitemap into root rm public/sitemap.xml -mv public/en/sitemap.xml public/sitemap.xml +mv public/en/sitemap.xml public/ + +# Clear Hugo translated content, which we don't yet use rm -rf public/ja rm -rf public/ko