https://www.shift2bikes.org/sitemap.xml builds and serves fine (200), but every entry is a relative path:
<url>
<loc>/pages/bike-summer/</loc>
</url>
<url>
<loc>/archive/get-lit/</loc>
<lastmod>2017-11-13T08:19:34+00:00</lastmod>
</url>
The sitemap protocol requires <loc> to be a fully qualified URL, so the 72 entries currently in the file are almost certainly being discarded.
Cause
site/config/_default/hugo.toml sets:
Hugo builds <loc> from each page's .Permalink, which is derived from baseURL, so the permalinks come out relative.
This is not a one-line fix
baseURL = "/" is load-bearing rather than an oversight. The theme uses absURL for essentially every asset, and for the calendar's own API calls:
site/themes/s2b_hugo_theme/layouts/partials/cal/scripts.html:140: url: '{{ absURL "api/events.php" }}',
site/themes/s2b_hugo_theme/layouts/partials/head-content.html:29: <link rel="icon" href="{{ absURL "favicon.ico" }}">
site/themes/s2b_hugo_theme/layouts/partials/cal/up-next.html:1: <script src="{{ absURL "lib/fullcalendar/core/main.min.js" }}"></script>
With baseURL = "/" these resolve same-origin, which is what lets the site work unchanged on localhost, on netlify deploy previews, and in production. Hardcoding the production URL into hugo.toml would make deploy previews and local dev load their scripts from, and fetch their event data from, www.shift2bikes.org.
Suggested approach
Set HUGO_BASEURL per netlify context rather than in hugo.toml, so each deploy gets the origin it is actually served from:
- production: the canonical
https://www.shift2bikes.org/
- deploy previews and branch deploys:
$DEPLOY_PRIME_URL
- local dev (
npm run dev, -e development): leave as /
Netlify exposes both URL and DEPLOY_PRIME_URL to the build, and hugo reads HUGO_BASEURL from the environment, so this can live in the command lines already present in netlify.toml.
Related
https://www.shift2bikes.org/sitemap.xmlbuilds and serves fine (200), but every entry is a relative path:The sitemap protocol requires
<loc>to be a fully qualified URL, so the 72 entries currently in the file are almost certainly being discarded.Cause
site/config/_default/hugo.tomlsets:Hugo builds
<loc>from each page's.Permalink, which is derived frombaseURL, so the permalinks come out relative.This is not a one-line fix
baseURL = "/"is load-bearing rather than an oversight. The theme usesabsURLfor essentially every asset, and for the calendar's own API calls:With
baseURL = "/"these resolve same-origin, which is what lets the site work unchanged on localhost, on netlify deploy previews, and in production. Hardcoding the production URL intohugo.tomlwould make deploy previews and local dev load their scripts from, and fetch their event data from,www.shift2bikes.org.Suggested approach
Set
HUGO_BASEURLper netlify context rather than inhugo.toml, so each deploy gets the origin it is actually served from:https://www.shift2bikes.org/$DEPLOY_PRIME_URLnpm run dev,-e development): leave as/Netlify exposes both
URLandDEPLOY_PRIME_URLto the build, and hugo readsHUGO_BASEURLfrom the environment, so this can live in thecommandlines already present innetlify.toml.Related
/404/. Worth excluding, most simply withsitemap: disablein the page's front matter.robots.txtwith aSitemap:line pointing here. That line becomes correct once this is fixed. See the discussion on the PR for shift2bikes.org/robots.txt is 404 #1068.