Giter Club home page Giter Club logo

mkdocs-localsearch's Introduction

mkdocs-localsearch

A MkDocs plugin to make the native "search" plugin work locally (file:// protocol).

NOTE: This plugin only works with the Material for MkDocs theme. If you need support for other themes, feel free to create a pull request.

Installation (Material v5)

To use the plugin with Material v5 projects:

  1. Install the plugin using pip: pip install mkdocs-localsearch
  2. Activate the plugin in mkdocs.yml, in addition to the search plugin:
    plugins:
        - search
        - localsearch
  3. Make sure that the use_directory_urls setting is set to false in mkdocs.yml to have filenames in the URL (required when using the file:/// protocol).
  4. Add a custom_dir entry to the theme section in mkdocs.yml:
    theme:
        name: material
        custom_dir: theme
  5. Create a new file, save it in your project dir as theme/main.html, and add the following content:
    {% extends "base.html" %}
    {% block config %}
    {% if "localsearch" in config["plugins"] %}
    <script src="https://unpkg.com/iframe-worker/polyfill"></script>
    <script src="{{ 'search/search_index.js' | url }}"></script>
    {% endif %}
    {% endblock %}
    Note: Don't use the extra_javascript option in mkdocs.yml to add the two scripts above. Scripts referenced via extra_javascript are placed at the bottom of the HTML page, i.e., after the search implementation, which is too late.
  6. If your documentation should work offline, i.e., without internet access:
    1. Open this file and save it as iframe-worker.js in your docs_dir.
      Example path: docs/assets/javascripts/iframe-worker.js
    2. Edit theme/main.html and change the following line:
      <script src="https://unpkg.com/iframe-worker/polyfill"></script>
      to this:
      <script src="{{ 'assets/javascripts/iframe-worker.js' | url }}"></script>
  7. If your project has a large search index (several MBytes), add the promise_delay setting:
    plugins:
        - search
        - localsearch:
            promise_delay: 100
    A delay of 100 ms worked with a search index of 24 MB (prebuilt index).
    Note that the promise_delay setting has a negative effect on performance (loading time will be increased).

Installation (Material v4)

To use the plugin with Material v4 projects:

  1. Install version 0.5.0 of the plugin using pip: pip install mkdocs-localsearch==0.5.0
  2. Activate the plugin in mkdocs.yml:
    plugins:
        - localsearch
  3. Add search_index.js to the extra_javascript section in mkdocs.yml:
    extra_javascript:
        - search/search_index.js
  4. Add a custom_dir entry to the theme section in mkdocs.yml:
    theme:
        name: material
        custom_dir: theme
  5. Open this file and save it in your project dir as theme/partials/header.html.
  6. Edit theme/partials/header.html and change the following line:
    {% if "search" in config["plugins"] %}
    to this:
    {% if "localsearch" in config["plugins"] %}
  7. Done!

mkdocs-localsearch's People

Contributors

wilhelmer avatar tjprogrammer avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.