Repository navigation
Conversation
…g#1082) The sitemap advertised at /sitemap.xml lists relative <loc> 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.
dduugg
force-pushed
the
issue-1082-sitemap-baseurl
branch
from
October 2, 2026 02:11
c93cef1 to
53c2373
Compare
Contributor
|
i don't know enough to evaluate this. maybe @carrythebanner or @nolessafool might? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1082.
https://www.shift2bikes.org/sitemap.xmlbuilds and serves (200), but every entry is a relative path:The sitemap protocol requires
<loc>to be a fully qualified URL, so search engines discard these entries. Hugo builds<loc>from each page's.Permalink, which derives frombaseURL, andbaseURL = "/".Why not just change baseURL in hugo.toml
Other things depend on
baseURLbeing relative. The theme resolves assets and the calendar's API calls throughabsURL:With a relative base those resolve same-origin, which is what lets one build work unchanged on localhost, on deploy previews, and in production. Hardcoding the production URL into
hugo.tomlwould make previews and local dev load assets from, and fetch event data from,www.shift2bikes.org.The change
baseURLstays/inhugo.toml.netlify.tomloverrides it per build context viaHUGO_BASEURL(hugo maps that env var ontobaseURL):https://www.shift2bikes.org(canonical host, matching the domain redirects at the top ofnetlify.toml)$DEPLOY_PRIME_URL(that build's own origin)/apiproxy resolve against the preview, not production/fromhugo.tomlIt is set inline in each
commandrather than in a[context.*.environment]table, because netlify only expands env vars like$DEPLOY_PRIME_URLinsidecommand. A[context.*.environment]value is a literal string, soHUGO_BASEURL = "$DEPLOY_PRIME_URL"there would hand hugo the literal text$DEPLOY_PRIME_URL.Verification
Built with hugo 0.152.2, reproducing each context's environment:
Confirmed on the live deploy preview for this PR as well:
The sitemap becomes absolute in the two deployed contexts, previews stay self-contained (the
/api/*proxy handles the preview-origin API calls), and local dev is unchanged.netlify.tomlstill parses as valid TOML.Notes
mainafter Let hugo build the 404 page directly (#862) #1083 merged, which resolved the conflict in the comment block above[context.deploy-preview]. Let hugo build the 404 page directly (#862) #1083 also removed/404/from the sitemap, so the production build now has no404entry.Sitemap:line added by Generate a robots.txt (#1068) #1080 (robots.txt) points at a valid sitemap.