Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sphinx builder: Use READTHEDOCS_CANONICAL_URL as html_baseurl #10226

Closed
benjaoming opened this issue Apr 5, 2023 · 3 comments
Closed

Sphinx builder: Use READTHEDOCS_CANONICAL_URL as html_baseurl #10226

benjaoming opened this issue Apr 5, 2023 · 3 comments
Labels
Bug A bug Improvement Minor improvement to code

Comments

@benjaoming
Copy link
Contributor

Proof of concept:

If this turns out to work well, I think we should escalate the pattern to replace the current implementation:

# For sphinx >=1.8 we can use html_baseurl to set the canonical URL.
# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_baseurl
if version_info >= (1, 8):
if not globals().get('html_baseurl'):
html_baseurl = context['canonical_url']
context['canonical_url'] = None

tldr; Why is it broken? What changed?

It can look odd that we have a behavior on Read the Docs Sphinx builder that looks broken and keeps coming up as an issue... I think it's an honest well-meaning implementation that's currently there. The outside understanding of what "canonical" means has just slowly pushed towards a new understanding.

The current implementation of "canonical URL", results in a meta tag canonical that simply points to the default version of a documentation, i.e. /en/stable.

It's possible to have the understanding that a "canonical URL" should always point to the default version. And that might have been the honest cause for the current implementation. But that's unfortunately an understanding of websites that doesn't match current-day usage of the canonical meta tag.

More and more chat clients and social media are reading the "canonical URL" in order to get a cleaned up version for a link, something resembling a "permalink". We started seeing the issue more and more since Mastodon uses the canonical meta field when parsing link data for preview cards.

So this ultimately means that preview cards and other auto-generated versions will not point to the same version as the link that got shared. And that's just wrong from a user's POV.

@benjaoming benjaoming added Improvement Minor improvement to code Needed: more information A reply from issue author is required Bug A bug labels Apr 5, 2023
@ashwinvis
Copy link

I saw this use case which looks at the SITEMAP_URL_BASE env variable.

https://github.com/pydata/pydata-sphinx-theme/blob/d98350b581b5dd804b918b1f6c82a51964957df8/docs/conf.py#L62

I wonder if overriding this might be an issue?

@benjaoming
Copy link
Contributor Author

Interesting! It looks safe from RTD injection since it's already guarded by a conditional: https://github.com/pydata/pydata-sphinx-theme/blob/d98350b581b5dd804b918b1f6c82a51964957df8/docs/conf.py#L59

If html_baseurl gets defined, RTD won't override it.

It's a bit hard to say what a project could need for development settings. Some might view local files with file:/// and some might be running sphinx-autobuild on http://127.0.0.1:8000. I think the safe default html_baseurl is simply /. But it's ultimately up to the project that wants to define it 👍

@github-project-automation github-project-automation bot moved this to Planned in 📍Roadmap Apr 11, 2023
@humitos humitos removed the Needed: more information A reply from issue author is required label Jun 26, 2023
@humitos
Copy link
Member

humitos commented Nov 7, 2023

We are moving away from the idea of adding/changing "magic" on our build process. Eventually, we should remove it all and only document how to use our environment variables properly on different doctools as #10246 mention. I'm closing this issue for now but we can re-open if we want to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug Improvement Minor improvement to code
Projects
Archived in project
Development

No branches or pull requests

3 participants