From c93cef1337fa1c30e34a3523f6e8f50dc80c81ed Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Fri, 10 Jul 2026 08:53:29 -0700 Subject: [PATCH] Set an absolute baseURL per netlify context for the sitemap (#1082) The sitemap advertised at /sitemap.xml lists relative paths, because baseURL is "/". The sitemap protocol requires fully qualified urls, so search engines reject these entries. baseURL stays "/" in hugo.toml, since the theme resolves assets and the calendar's /api calls through absURL, and a relative base is what lets the same build work on localhost, deploy previews, and prod. Instead, override it per netlify context: production -> https://www.shift2bikes.org ( canonical host ) deploy/branch deploy -> $DEPLOY_PRIME_URL ( that build's own origin ) Set inline in `command`, since netlify only expands env vars like $DEPLOY_PRIME_URL there, not in a [context.*.environment] table. On previews the assets and /api proxy then resolve against the preview rather than production. --- netlify.toml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/netlify.toml b/netlify.toml index 41033891..7cb429b7 100644 --- a/netlify.toml +++ b/netlify.toml @@ -11,17 +11,28 @@ [build.environment] # extra environment variables if needed. +# HUGO_BASEURL overrides `baseURL` in site/config/_default/hugo.toml +# ( which stays "/" so local dev and any un-cased build work on any host ). +# hugo needs an absolute baseURL for a valid sitemap: entries must be +# fully qualified urls, so relative paths get rejected by search engines. +# cf https://github.com/shift-org/shift-docs/issues/1082 +# +# note: netlify only expands env vars like $DEPLOY_PRIME_URL inside `command`, +# not inside a [context.*.environment] table, so we set it inline here. + # we need to manually copy the 404 page over for now, in every environment # cf https://github.com/shift-org/shift-docs/issues/862 [context.deploy-preview] # -D builds draft content for deploy previews # ( the doubledash is needed to pass the argument through to hugo ) # cf https://docs.netlify.com/site-deploys/deploy-previews/ - command = 'npm run deploy -- -D' + # DEPLOY_PRIME_URL is this preview's own origin, so assets and the + # /api proxy still resolve against the preview rather than production. + command = 'HUGO_BASEURL="$DEPLOY_PRIME_URL" npm run deploy -- -D' [context.branch-deploy] # operates on custom branches, same as deploy-preview. - command = 'npm run deploy -- -D' + command = 'HUGO_BASEURL="$DEPLOY_PRIME_URL" npm run deploy -- -D' [context.production] # see this guide about why we do this funky thing with ssh: @@ -31,9 +42,10 @@ # and replace with one of the 'npm run deploy' commands from above. # # NOTE: This pulls new code to the api server! - # drafts are excluded (no `-D` option) for prod build. - # - command = 'npm run deploy && mkdir -p ~/.ssh && echo -e "${SSH_KEY//_/\\n}" > ~/.ssh/id_rsa && chmod og-rwx ~/.ssh/id_rsa && ssh -v -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@api.shift2bikes.org "cd /opt/shift-docs && ./shift pull" || (echo "you seem to be building without ssh access - see https://github.com/shift-org/shift-docs#netlify-deployment for details" ; /bin/false)' + # drafts are excluded (no `-D` option) for prod build. + # HUGO_BASEURL is the canonical host ( matching the domain redirects above ), + # so the sitemap points at the version of the site we actually serve. + command = 'HUGO_BASEURL="https://www.shift2bikes.org" npm run deploy && mkdir -p ~/.ssh && echo -e "${SSH_KEY//_/\\n}" > ~/.ssh/id_rsa && chmod og-rwx ~/.ssh/id_rsa && ssh -v -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@api.shift2bikes.org "cd /opt/shift-docs && ./shift pull" || (echo "you seem to be building without ssh access - see https://github.com/shift-org/shift-docs#netlify-deployment for details" ; /bin/false)' ## --------------------------------------------------------------------------- ## domain redirects to serve alternative domains. First, we canonicalize