Closed dmalan closed 3 weeks ago
The canonical
link
tag is not outputted when we build locally withmake dirhtml
, though.
I'd like to reproduce the behavior reported on this issue locally. That will help us to debug the problem in an easier way. However, I wasn't able to do this.
I added the following to the conf.py
trying to reproduce this problem and I couldn't:
# conf.py
html_context = {
'canonical_url': 'https://cs50.readthedocs.io/',
}
# ... and ...
html_theme_options.update({
'canonical_url': 'https://cs50.readthedocs.io/',
})
What would be the correct combination of html_context
/html_theme_options
we need to define here?
Note I got the value for
canonical_url
from the Read the Docs production database, to use the same value than there.
canonical_url
is deprecated and shouldn't be used anymore, you should html_baseurl
now instead.
You can add the following snippet in your conf.py
if you are building on Read the Docs:
import os
# Define the canonical URL if you are using a custom domain on Read the Docs
html_baseurl = os.environ.get("READTHEDOCS_CANONICAL_URL", "")
Let me know if that solves the issue. Feel free to re-open the issue if it doesn't.
Problem
For https://cs50.readthedocs.io/, the source for which is at https://github.com/cs50/cs50.readthedocs.io, we're using Sphinx HtmlDir at https://readthedocs.org/dashboard/cs50/advanced/, so that our URLs are of the form, e.g.,
https://cs50.readthedocs.io/code/
instead ofhttps://cs50.readthedocs.io/code.html
.However, we noticed that
sphinx_rtd_theme==1.0.0
is still outputtingper
https://github.com/readthedocs/sphinx_rtd_theme/blob/master/sphinx_rtd_theme/layout.html#L52-L55
which we gather might be happening because
conf.py.tmpl
is settingcanonical_url
at https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl#L98. (Somehow, at least,theme_canonical_url
is being set but notpageurl
.) The result is that, e.g., Chrome on iOS, when you click the Share icon, copies that URL to the user's clipboard rather than the HtmlDir version thereof, so the recipient ends up with a 404.The canonical
link
tag is not outputted when we build locally withmake dirhtml
, though.Reproducible Project
https://cs50.readthedocs.io/code/
Error Logs/Results
Expected Results
Build should be outputting HtmlDir-style canonical URLs like:
Environment Info
sphinx_rtd_theme==1.0.0