shift-org / shift-org/shift-docs
sitemap.xml emits relative <loc> values, so search engines reject it
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 30
- Forks
- 25
- Avg merge
- 9m
- Merged PRs (30d)
- 1
Description
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:
baseURL = "/"
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
- The sitemap also lists
/404/. Worth excluding, most simply withsitemap: disablein the page's front matter. - #1068 adds a
robots.txtwith aSitemap:line pointing here. That line becomes correct once this is fixed. See the discussion on the PR for #1068.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with site/config/_default/hugo.toml and the existing command lines in netlify.toml, then review the absURL uses in the listed theme partials to preserve local and preview behavior. Configure the base URL per Netlify context and verify that sitemap.xml emits fully qualified loc values for all entries, while checking the related /404/ and robots.txt behavior described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- hugo, javascript
- Domain
- build-system, devops, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100