8000 Custom Search Worker setting is ignored · Issue #2973 · squidfunk/mkdocs-material · GitHub
[go: up one dir, main page]

Skip to content

Custom Search Worker setting is ignored #2973

@xvandish

Description

@xvandish

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_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

  1. setup a barebones mkdocs repo however you want (mkdocs new)
  2. add the search plugin in mkdocs.yaml. How-to is described here
  3. create a directory overrides
  4. set overrides as the custom_dir by setting custom_dir: overrides in mkdocs.yml under the theme block. How-to described here here
  5. Add a main.html file in the overrides directory. 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 %}
  1. Add a worker.js file in the overrides directory. 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:
  - search

System information

  • Operating system: Mac OS Catalina (10.15.7)
  • Browser: Google Chrome (92.0.4515.131)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      2A96
      0