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

Algolia docsearch #3159

Merged
merged 15 commits into from
Jul 26, 2023
Merged

Conversation

agriyakhetarpal
Copy link
Member

@agriyakhetarpal agriyakhetarpal commented Jul 18, 2023

Description

This PR adds Algolia DocSearch v3 since our application was accepted recently. Third-party search functionality is not supported with PyData Sphinx Theme yet (pydata/pydata-sphinx-theme#202, pydata/pydata-sphinx-theme#795

Therefore, manual templates are added along with the sphinx-docsearch extension from Algolia to render the search bar. This disables the default search bar.

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python run-tests.py --all
  • The documentation builds: $ python run-tests.py --doctest

You can run unit and doctests together at once, using $ python run-tests.py --quick.

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@codecov
Copy link

codecov bot commented Jul 18, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (79af68d) 99.71% compared to head (b995df8) 99.71%.

❗ Current head b995df8 differs from pull request most recent head e8b482d. Consider uploading reports for the commit e8b482d to get more accurate results

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3159   +/-   ##
========================================
  Coverage    99.71%   99.71%           
========================================
  Files          248      248           
  Lines        18763    18763           
========================================
  Hits         18709    18709           
  Misses          54       54           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@agriyakhetarpal
Copy link
Member Author

agriyakhetarpal commented Jul 21, 2023

Some updates: there are definitely ways to make Algolia work with the PyData Sphinx Theme—the sphinx-docsearch extension is just a wrapper and does the same thing as adding the necessary JavaScript files in html_js_files, Algolia's custom CSS in html_css_files, and overrides the search button template at the time the Sphinx builder performs the initialisation. Here are some references of how some other libraries' documentation websites built with PST add the search box – all of them use the same, manual process:

  1. sgkit documentation (slightly off-set position, they override the fullscreen overlay. They use Algolia v2 however, the other ones below use v3)
  2. Orchest documentation (they simply add their own search field in the navbar with PyData's search icon. We can remove the search icon)
  3. DeterminedAI documentation (they have their own colour scheme and have customised their theme extensively, but their location is in the left sidebar and it works)
  4. Deepchecks documentation (they seem to align the Algolia overlay pretty well to 'join' the navbar just above it)

There seems to be a require.js error in our case both locally and on readthedocs when I try to follow their build processes (it should work out of the box using the above solution of adding the JavaScript and CSS files) so I probably need to investigate. I am not sure how to debug it so I have filed an issue in the Algolia forum on Discourse to seek help and will follow up on any responses I receive.

@agriyakhetarpal
Copy link
Member Author

agriyakhetarpal commented Jul 22, 2023

This should be ready for review/merge now once tests pass—apparently the error about require.js came from nbsphinx since it is used to load interactive widgets in the notebooks (ipywidgets). It also happens to break a lot of other Sphinx extensions that rely on external JavaScript. This explains #3165 (comment), so we now know why the rendered notebooks won't display sliders in the docs, but I think it is a minor compromise since users can download the notebooks anyway or run them in Colab.

I also added a few CSS customisations so that the elements resemble the PyData Sphinx Theme. The new, blazing-fast search can be tried here: https://pybamm--3159.org.readthedocs.build/en/3159/

@agriyakhetarpal agriyakhetarpal marked this pull request as ready for review July 22, 2023 01:13
Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

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

That's super fast! Thanks for working on this, @agriyakhetarpal!

@agriyakhetarpal
Copy link
Member Author

Before we merge this I just want to make sure that the position is correct on smaller screens and try it on a Windows system which uses Ctrl instead of in the search box

@Saransh-cpp
Copy link
Member

Sounds good, let us know when this is ready to merge.

@agriyakhetarpal
Copy link
Member Author

Good to go now!

@valentinsulzer valentinsulzer merged commit 3999609 into pybamm-team:develop Jul 26, 2023
@agriyakhetarpal agriyakhetarpal deleted the algolia-docsearch branch July 26, 2023 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants