- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Custom Search Worker setting is ignored #2973
Comments
I'm happy to contribute and help out, but I may not be able to do any work until this weekend or next. Also, I understand the documented implementation of custom search may no longer how you'd like to go about this - things change all the time. |
Okay, so I've managed to set aside some time to look into this. Here are some thoughts: Search plugin dependencySearch indexAlthough it should be possible to define a custom search worker to completely alter the search behavior, Material for MkDocs will by default always load The mkdocs-material/src/assets/javascripts/bundle.ts Lines 100 to 104 in 2d411a2
If the search index should not be loaded, it can just be set to a {
"config": {
"lang": []
},
"docs": []
} Search formNote that the mkdocs-material/src/partials/header.html Lines 132 to 139 in 2d411a2
While the search plugin might not be necessary for external third-party search, it's easier to check from a template perspective. If the search box should be shown regardless of the presence of the search plugin, omitting the need to build the search index at all, the partial can be overridden by using theme extension. Search worker overrideSo, now, to allow a custom search worker given all the constraints outlined before, I think that it's okay to add the Lines 364 to 370 in 2d411a2
I've added it back in 441381b. On a side note, please understand that we cannot provide further support for implementing a custom search worker beyond what's already listed in the documentation. The inline documentation is pretty extensive and you're invited to open further discussions to ask other users for help on a custom implementation. If you, however, run into another behavior which is inconsistent with what is listed in the documentation, feel free to create another issue. |
Released as part of 7.2.6. |
Contribution guidelines
I've found a bug and checked that ...
mkdocs
orreadthedocs
themescustom_dir
,extra_javascript
andextra_css
Description
As discussed in #2972, at the moment custom search does not work the way it's described in the documentation here.
The
worker
used to implement search is not configurable in the way thats described by the documentation, which is to override theconfig
block like so:At the moment, however, this doesn't actually configure the
worker
thats used, the default/built-in implementation here is always used.Expected behaviour
I would expect the following block of code set in
overrides/main.html
to load a worker at the path
overrides/awesomeWorker.js
and have the search html input pass messages to it for consumption and and processing.Actual behaviour
The worker mentioned in the
config
block is not called/passed messages by the search input, so effectively nothing happens.Steps to reproduce
mkdocs new
)search
plugin inmkdocs.yaml
. How-to is described hereoverrides
overrides
as thecustom_dir
by settingcustom_dir: overrides
inmkdocs.yml
under thetheme
block. How-to described here heremain.html
file in theoverrides
directory. Set it's file contents to:worker.js
file in theoverrides
directory. Set its file contents to:Now type something in the search. You should see the default
search.*.js
worker still loaded and working in the background, instead of our custom worker.Package versions
3.9
1.2.2
7.2.4
Configuration
System information
The text was updated successfully, but these errors were encountered: