-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
DirHTML builder generates wrong canonical links #9730
Comments
This is affecting the Pallets docs on Read the Docs. Apparently some browsers "Share Link" feature uses a canonical URL if it's available, so sharing links to docs shares invalid links. Is there anything I can do to help get this merged and released? Also, somehow I didn't realize this has been generated by Sphinx since 1.8 in 2018, both Read the Docs and Pallets-Sphinx-Theme have code for generating this tag as well. |
I added a workaround for this issue to Pallets-Sphinx-Themes. A hook will detect if the dirhtml builder is in use and if the |
A quick suggestion for fixing this bug: Since a lot of projects and themes may have developed behavior based on how the currently undocumented For instance: tldr; I don't really know if Idea? 💡Starting from scratch with 3 new variables might be easier to handle and customize canonical URLs?
|
@benjaoming thanks for the suggestion, having a specific variable for the canonical URL can indeed be useful. Let me clarify though that the core of this issue is that the current |
I wrote this, and I think it works... but not sure if we'll merge it nor if it's a recommendable approach https://github.com/readthedocs/sphinx_rtd_theme/blob/6beecce44759257ed584f2fdb0357f2aec0ad01a/sphinx_rtd_theme/layout.html#L62-L77 (afaict, it's also going to keep on working, even if |
@AA-Turner I would like to move forwards with a fix for this issue. What do you think about the approach to add new context variables specifically for canonical URLs as laid out in #9730 (comment) ? It would be nice to have some level of assurance that the approach is well-understood before implementing it. |
@benjaoming Referencing to your suggestion, since my project is not using the rtd theme but furo theme, I tried to apply the same check to the Do you have any advice? What I want to achieve is remove the default canonical and set my own in the Thanks in advance. |
@angelinekwan The reason why we're doing it in the template of sphinx-rtd-theme is... well it's complicated 😇 But if given the choice, it's better to do create new context variables like @davidism's approach => #9730 (comment) I'm not sure why you'd end up with duplicate tags, sounds like a template block isn't being overwritten as intended... but if it's possible to fix the existing context variable, you wouldn't have to manipulate the template. Sorry, if it's not helpful. It's worrying that both template developers and project owners are doing workarounds for this bug, it really needs to be addressed upstream. Would appreciate if a Sphinx developer can give some sort of endorsement to the suggested approach? |
I think it ended up duplicate tags because the overwrite is not in the header template file which has the default canonical tag - I don't think i can access it. Agree this issue should be fix on the upstream... Thanks for checking! |
Upstream Sphinx doesn't construct canonical links correctly for the DirectoryHTMLBuilder. When I introduced #650, it included a bug for `index.html` pages. This PR adds a proper fix with tests this time to make sure that canonical links are what they should be. This PR is a follow up of #1258 and reverts the change in `layout.html`. Checking the canonical link shouldn't be done in the template. It's reported here: [#9730](sphinx-doc/sphinx#9730)
@benjaoming @lexming do you still support this approach? If so I would accept a PR for it. A |
Thanks for the update on this @AA-Turner . I'm not really interested in that fine-grained customization of canonical URLs though. I guess it can be useful to some, but the original purpose of this issue was about generating non-existent canonical URLs, which is already fixed. So I suggest to open a different issue for those customization options. |
hey! I'm gonna have to ghost this, as I'm not able to find time and get far enough into the substance again right now 🙈 But I think the original comment still stands, a good solution to the problem would be to start from scratch with new variables & definitions. You won't get bogged down by all the hacks that are floating around for the old variables. |
Describe the bug
Using the
dirhtml
builder results in pages with canonical links of the formfor the index document
_website/search/index.html
How to Reproduce
Expected behavior
The canonical link has either the form
or
Your project
sphinx-canonical-links.zip
Screenshots
No response
OS
Unix
Python version
3.9
Sphinx version
4.x
Sphinx extensions
No response
Extra tools
No response
Additional context
sphinx-canonical-links.zip
The text was updated successfully, but these errors were encountered: