-
Notifications
You must be signed in to change notification settings - Fork 919
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
Algolia search, fix: show search box in the sidebar #1651
Conversation
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 completely makes sense that the IDs should be unique!
I'd like to propose that this be solved more simply by using, say, an ordinal (.Ordinal
) as a suffix to the ID. Such an approach will confine changes to layouts/partials/search-input.html
. It will also make it easier to keep things dry during the initializing calls to docsearch()
: we'll be able to iterate from 0 to the number_of_input_searches - 1 in our calls to that function.
WDYT?
(Also, I can't recall if we have an easy way to test this?)
While authoring my PR, I had exactly the same idea of using an I tried to alter my PR following your recommendations given above and ended up with this code:
and for the output of the search box
First I liked this minimal solution. It works perfectly fine when publishing (via command How to proceed here?
Good point. Fortunately, I do have a algolia enabled site at hand, but I don't have a solution how to test this in an easy manner in this repo. |
Thanks for trying all of that out. To be clear: so both the use of That's strange. Regardless, consider using <div id="docsearch-{{ mod .Ordinal 2 }}"></div> Or use |
You are welcome.
Yes, the solution outline above results in different ordinal values depending on the hugo command used.
Indeed.
Great idea. I modified my PR accordingly, it's shorter and cleaner now and works like a charm! Thanks for your input, looking forward seeing this merged soon! |
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.
Much cleaner, as you point out.
A few more comments, see inline.
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.
Wonderful, thanks!
When enabling algolia search, only the search box in the navbar appears, the search box in the sidebar doesn't show up. As correctly analysed here, this is due to the fact that currently both search boxes use the same id in their corresponding div element (which violates the principle that ids should be unique(!)).
This PR solves this issue, both search boxes show up with this patch applied. This PR also updates the documentation on algolia search in the user guide: we now have to provide two
docsearch
functions in the docsearch javascript code.