-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Contribution guidelines
- I've read the contribution guidelines and wholeheartedly agree
I've found a bug and checked that ...
- ... the problem doesn't occur with the
mkdocsorreadthedocsthemes - ... the problem persists when all overrides are removed, i.e.
custom_dir,extra_javascriptandextra_css - ... the documentation does not mention anything about my problem
- ... there are no open or closed issues that are related to my problem
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 the config block like so:
{% block config %}
{{ super() }}
<script>
var __search = {
worker: "<url>"
}
</script>
{% endblock %}
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
{% block config %}
{{ super() }}
<script>
var __search = {
worker: "./awesomeWorker.js"
}
</script>
{% endblock %}
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
- setup a barebones mkdocs repo however you want (
mkdocs new) - add the
searchplugin inmkdocs.yaml. How-to is described here - create a directory
overrides - set
overridesas thecustom_dirby settingcustom_dir: overridesinmkdocs.ymlunder thethemeblock. How-to described here here - Add a
main.htmlfile in theoverridesdirectory. Set it's file contents to:
{% extends "base.html" %}
{% block htmltitle %}
<title>Lorem ipsum dolor sit amet</title>
{% endblock %}
{% block config %}
{{ super() }}
<script>
var __search = {
worker: "./worker.js"
}
</script>
{% endblock %}
- Add a
worker.jsfile in theoverridesdirectory. Set its file contents to:
console.log('whats going on')
export async function handler(message) {
console.log({ message })
}
addEventListener("message", async ev => {
postMessage(await handler(ev.data))
})
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
- Python:
3.9 - MkDocs:
1.2.2 - Material:
7.2.4
Configuration
site_name: My Docs
theme:
name: material
custom_dir: overrides
plugins:
- searchSystem information
- Operating system: Mac OS Catalina (10.15.7)
- Browser: Google Chrome (92.0.4515.131)