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

Fix search in dirhtml output #7192

Merged
merged 3 commits into from Feb 22, 2020
Merged

Fix search in dirhtml output #7192

merged 3 commits into from Feb 22, 2020

Conversation

vsalvino
Copy link
Contributor

@vsalvino vsalvino commented Feb 21, 2020

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 a role="main" HTML element. This change fixes the search to work correctly in both cases.

Feature or Bugfix

  • Bugfix

Detail

When built in dirhtml, URLs such as docs/test.html now become docs/test/. However, in many cases the search was performing incorrect ajax queries such as docs/test/index/ and docs/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 with role=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.

@@ -63,6 +63,9 @@ var Search = {
htmlElement.innerHTML = htmlString;
$(htmlElement).find('.headerlink').remove();
docContent = $(htmlElement).find('[role=main]')[0];
if(docContent === undefined) {
return "";
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

@tk0miya tk0miya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@tk0miya
Copy link
Member

tk0miya commented Feb 22, 2020

I confirmed this works fine on my local.

@tk0miya tk0miya merged commit 31a4bfb into sphinx-doc:2.4.x Feb 22, 2020
@tk0miya
Copy link
Member

tk0miya commented Feb 22, 2020

Merged. Thank you for your contribution!

@rdb
Copy link
Contributor

rdb commented Mar 7, 2020

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?

@vsalvino
Copy link
Contributor Author

vsalvino commented Mar 9, 2020

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?

@sciunto
Copy link

sciunto commented May 20, 2020

I think so. scikit-image/scikit-image#4616

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants