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
Fix search in dirhtml output #7192
Conversation
@@ -63,6 +63,9 @@ var Search = { | |||
htmlElement.innerHTML = htmlString; | |||
$(htmlElement).find('.headerlink').remove(); | |||
docContent = $(htmlElement).find('[role=main]')[0]; | |||
if(docContent === undefined) { | |||
return ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be helpful if there are debug message in JS console.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I posted it as an another PR: #7194
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks!
I confirmed this works fine on my local. |
Merged. Thank you for your contribution! |
Note that a side effect of this change isn't just that the AJAX requests become absolute, but also that the links themselves become absolute links, including for non-dirhtml builders. Was this intended? |
It wasn't necessarily indented that links become absolute. However, the links were being incorrectly generated and were producing all 404s (in dirhtml mode). So the intention was to generate the correct URLs. Is this change causing breakage? |
I think so. scikit-image/scikit-image#4616 |
Subject: The built-in JavaScript search exhibits a rather major bug in that it seems to completely break when the output is generated in
dirhtml
mode, OR if a custom theme is missing arole="main"
HTML element. This change fixes the search to work correctly in both cases.Feature or Bugfix
Detail
When built in
dirhtml
, URLs such asdocs/test.html
now becomedocs/test/
. However, in many cases the search was performing incorrect ajax queries such asdocs/test/index/
anddocs/test/.html
. My change looks for the correct URL when making ajax calls in the search.These invalid URLs of course trigger 404s which in turn exposes another bug when trying to process the response HTML and look for a
[role='main']
element. This could also have been causing issues with custom themes that do not implement an element withrole=main
. My change also handles that case: if that element does not exist, an empty string instead is returned.Relates
There are a couple related issues, which are marked as "closed", but the issue still persists on sphinx 2.4.x. See #6244 , #6257 , #6387
Please provide feedback on if this should be merged into a different branch, or if my Pull Request is missing anything.