Skip to content

Fix sitemap URLs: every entry currently 404s - #14

Open
bloxster wants to merge 1 commit into
zodl-inc:masterfrom
bloxster:fix/sitemap-url-scheme
Open

Fix sitemap URLs: every entry currently 404s#14
bloxster wants to merge 1 commit into
zodl-inc:masterfrom
bloxster:fix/sitemap-url-scheme

Conversation

@bloxster

Copy link
Copy Markdown

Every URL in the published sitemap returns 404.

html_baseurl ends in /en/latest/, and sphinx-sitemap 2.2.0 defaults sitemap_url_scheme to {lang}{version}{link}, so the language segment is emitted a second time:

https://zcash.readthedocs.io/en/latest/en/rtd_pages/basics.html   404   (what the sitemap says)
https://zcash.readthedocs.io/en/latest/rtd_pages/basics.html      200   (what the site serves)

Setting sitemap_url_scheme = "{link}" stops the duplication, since the base URL already carries both segments. ({version} expands to nothing here, as version is empty — only the language is duplicated.)

Second, smaller fix. html_baseurl was hardcoded to /en/latest/, so a build of any other version advertised latest URLs regardless. Read the Docs serves this project at /en/master/ as well. It now prefers READTHEDOCS_CANONICAL_URL, which Read the Docs sets to the canonical URL of the version under build, and falls back to the previous literal for local builds. This uses the os import already present at the top of the file.

Verification. Built a minimal project against sphinx-sitemap==2.2.0 (the pinned version) with this exact configuration:

generated <loc>
before …/en/latest/en/index.html — 404 live
after, local build …/en/latest/index.html — 200 live
after, READTHEDOCS_CANONICAL_URL=…/en/master/ …/en/master/index.html — 200 live

Worth noting the two versions currently publish the same content under different version stamps in search results, which this does not address — but a sitemap that resolves is a precondition for search engines sorting that out.

html_baseurl ends in /en/latest/, and sphinx-sitemap 2.2.0 defaults
sitemap_url_scheme to "{lang}{version}{link}", so the language segment is
emitted twice and the sitemap advertises /en/latest/en/<page>.html. Setting the
scheme to "{link}" stops that.

html_baseurl now also prefers READTHEDOCS_CANONICAL_URL, so a build of
/en/master/ no longer advertises /en/latest/ URLs. Uses the os import already
present in the file.

Verified against sphinx-sitemap 2.2.0, the pinned version, with a minimal
build in both modes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant