Skip to content

MkPluginFlow

Show source on GitHub

Node showing info about the different stages of an MkDocs plugin.

Example: Regular

Jinja

{{ "mkdocs.contrib.search.SearchPlugin" | to_class | MkPluginFlow }}

Python

MkPluginFlow(<class 'mkdocs.contrib.search.SearchPlugin'>)

SearchPlugin

on_config

Add plugin templates and scripts to config.

Source
mkdocs.contrib.search.SearchPlugin.on_config
def on_config(self, config: MkDocsConfig, **kwargs) -&gt; MkDocsConfig:
    """Add plugin templates and scripts to config."""
    if config.theme.get('include_search_page'):
        config.theme.static_templates.add('search.html')
    if not config.theme.get('search_index_only'):
        path = os.path.join(base_path, 'templates')
        config.theme.dirs.append(path)
        if 'search/main.js' not in config.extra_javascript:
            config.extra_javascript.append('search/main.js')  # type: ignore
    if self.config.lang is None:
        # lang setting undefined. Set default based on theme locale
        validate = _PluginConfig.lang.run_validation
        self.config.lang = validate(config.theme.locale.language)
    # The `python` method of `prebuild_index` is pending deprecation as of version 1.2.
    # TODO: Raise a deprecation warning in a future release (1.3?).
    if self.config.prebuild_index == 'python':
        log.info(
            "The 'python' method of the search plugin's 'prebuild_index' config option "
            "is pending deprecation and will not be supported in a future release."
        )
    return config
Hook info

The config event is the first event called on build and is run immediately after the user configuration is loaded and validated. Any alterations to the config should be made here.

Parameters:

Name Type Description Default
config MkDocsConfig

global configuration object

required

on_pre_build

Create search index instance for later use.

Source
mkdocs.contrib.search.SearchPlugin.on_pre_build
def on_pre_build(self, config: MkDocsConfig, **kwargs) -&gt; None:
    """Create search index instance for later use."""
    self.search_index = SearchIndex(**self.config)
Hook info

The pre_build event does not alter any variables. Use this event to call pre-build scripts.

Parameters:

Name Type Description Default
config MkDocsConfig

global configuration object

required

on_post_build

Build search index.

Source
mkdocs.contrib.search.SearchPlugin.on_post_build
def on_post_build(self, config: MkDocsConfig, **kwargs) -&gt; None:
    """Build search index."""
    output_base_path = os.path.join(config.site_dir, 'search')
    search_index = self.search_index.generate_search_index()
    json_output_path = os.path.join(output_base_path, 'search_index.json')
    utils.write_file(search_index.encode('utf-8'), json_output_path)

    assert self.config.lang is not None
    if not config.theme.get('search_index_only'):
        # Include language support files in output. Copy them directly
        # so that only the needed files are included.
        files = []
        if len(self.config.lang) &gt; 1 or 'en' not in self.config.lang:
            files.append('lunr.stemmer.support.js')
        if len(self.config.lang) &gt; 1:
            files.append('lunr.multi.js')
        if 'ja' in self.config.lang or 'jp' in self.config.lang:
            files.append('tinyseg.js')
        for lang in self.config.lang:
            if lang != 'en':
                files.append(f'lunr.{lang}.js')

        for filename in files:
            from_path = os.path.join(base_path, 'lunr-language', filename)
            to_path = os.path.join(output_base_path, filename)
            utils.copy_file(from_path, to_path)
Hook info

The post_build event does not alter any variables. Use this event to call post-build scripts.

Parameters:

Name Type Description Default
config MkDocsConfig

global configuration object

required

on_page_context

Add page to search index.

Source
mkdocs.contrib.search.SearchPlugin.on_page_context
def on_page_context(self, context: TemplateContext, page: Page, **kwargs) -&gt; None:
    """Add page to search index."""
    self.search_index.add_entry_from_context(page)
Hook info

The page_context event is called after the context for a page is created and can be used to alter the context for that specific page only.

Parameters:

Name Type Description Default
context TemplateContext

dict of template context variables

required
page Page

mkdocs.structure.pages.Page instance

required
config MkDocsConfig

global configuration object

required
nav Navigation

global navigation object

required

on_post_build

Build search index.

Source
mkdocs.contrib.search.SearchPlugin.on_post_build
def on_post_build(self, config: MkDocsConfig, **kwargs) -&gt; None:
    """Build search index."""
    output_base_path = os.path.join(config.site_dir, 'search')
    search_index = self.search_index.generate_search_index()
    json_output_path = os.path.join(output_base_path, 'search_index.json')
    utils.write_file(search_index.encode('utf-8'), json_output_path)

    assert self.config.lang is not None
    if not config.theme.get('search_index_only'):
        # Include language support files in output. Copy them directly
        # so that only the needed files are included.
        files = []
        if len(self.config.lang) &gt; 1 or 'en' not in self.config.lang:
            files.append('lunr.stemmer.support.js')
        if len(self.config.lang) &gt; 1:
            files.append('lunr.multi.js')
        if 'ja' in self.config.lang or 'jp' in self.config.lang:
            files.append('tinyseg.js')
        for lang in self.config.lang:
            if lang != 'en':
                files.append(f'lunr.{lang}.js')

        for filename in files:
            from_path = os.path.join(base_path, 'lunr-language', filename)
            to_path = os.path.join(output_base_path, filename)
            utils.copy_file(from_path, to_path)
Hook info

The post_build event does not alter any variables. Use this event to call post-build scripts.

Parameters:

Name Type Description Default
config MkDocsConfig

global configuration object

required
## SearchPlugin
<div class="speech bottom" markdown="1">
## [on_config](https://www.mkdocs.org/dev-guide/plugins/#on_config)

Add plugin templates and scripts to config.

??? quote "Source"
    ```` {.python  title='mkdocs.contrib.search.SearchPlugin.on_config' linenums='65'}
    def on_config(self, config: MkDocsConfig, **kwargs) -&gt; MkDocsConfig:
        """Add plugin templates and scripts to config."""
        if config.theme.get('include_search_page'):
            config.theme.static_templates.add('search.html')
        if not config.theme.get('search_index_only'):
            path = os.path.join(base_path, 'templates')
            config.theme.dirs.append(path)
            if 'search/main.js' not in config.extra_javascript:
                config.extra_javascript.append('search/main.js')  # type: ignore
        if self.config.lang is None:
            # lang setting undefined. Set default based on theme locale
            validate = _PluginConfig.lang.run_validation
            self.config.lang = validate(config.theme.locale.language)
        # The `python` method of `prebuild_index` is pending deprecation as of version 1.2.
        # TODO: Raise a deprecation warning in a future release (1.3?).
        if self.config.prebuild_index == 'python':
            log.info(
                "The 'python' method of the search plugin's 'prebuild_index' config option "
                "is pending deprecation and will not be supported in a future release."
            )
        return config

    ````


??? info "Hook info"
    ::: mkdocs.plugins.BasePlugin.on_config
        options:
          show_source: False
          show_root_toc_entry: False


</div>
<div class="speech bottom" markdown="1">
## [on_pre_build](https://www.mkdocs.org/dev-guide/plugins/#on_pre_build)

Create search index instance for later use.

??? quote "Source"
    ```` {.python  title='mkdocs.contrib.search.SearchPlugin.on_pre_build' linenums='87'}
    def on_pre_build(self, config: MkDocsConfig, **kwargs) -&gt; None:
        """Create search index instance for later use."""
        self.search_index = SearchIndex(**self.config)

    ````


??? info "Hook info"
    ::: mkdocs.plugins.BasePlugin.on_pre_build
        options:
          show_source: False
          show_root_toc_entry: False


</div>
<div class="speech bottom" markdown="1">
## [on_post_build](https://www.mkdocs.org/dev-guide/plugins/#on_post_build)

Build search index.

??? quote "Source"
    ```` {.python  title='mkdocs.contrib.search.SearchPlugin.on_post_build' linenums='95'}
    def on_post_build(self, config: MkDocsConfig, **kwargs) -&gt; None:
        """Build search index."""
        output_base_path = os.path.join(config.site_dir, 'search')
        search_index = self.search_index.generate_search_index()
        json_output_path = os.path.join(output_base_path, 'search_index.json')
        utils.write_file(search_index.encode('utf-8'), json_output_path)

        assert self.config.lang is not None
        if not config.theme.get('search_index_only'):
            # Include language support files in output. Copy them directly
            # so that only the needed files are included.
            files = []
            if len(self.config.lang) &gt; 1 or 'en' not in self.config.lang:
                files.append('lunr.stemmer.support.js')
            if len(self.config.lang) &gt; 1:
                files.append('lunr.multi.js')
            if 'ja' in self.config.lang or 'jp' in self.config.lang:
                files.append('tinyseg.js')
            for lang in self.config.lang:
                if lang != 'en':
                    files.append(f'lunr.{lang}.js')

            for filename in files:
                from_path = os.path.join(base_path, 'lunr-language', filename)
                to_path = os.path.join(output_base_path, filename)
                utils.copy_file(from_path, to_path)

    ````


??? info "Hook info"
    ::: mkdocs.plugins.BasePlugin.on_post_build
        options:
          show_source: False
          show_root_toc_entry: False


</div>
<div class="speech bottom" markdown="1">
## [on_page_context](https://www.mkdocs.org/dev-guide/plugins/#on_page_context)

Add page to search index.

??? quote "Source"
    ```` {.python  title='mkdocs.contrib.search.SearchPlugin.on_page_context' linenums='91'}
    def on_page_context(self, context: TemplateContext, page: Page, **kwargs) -&gt; None:
        """Add page to search index."""
        self.search_index.add_entry_from_context(page)

    ````


??? info "Hook info"
    ::: mkdocs.plugins.BasePlugin.on_page_context
        options:
          show_source: False
          show_root_toc_entry: False


</div>
<div class="speech" markdown="1">
## [on_post_build](https://www.mkdocs.org/dev-guide/plugins/#on_post_build)

Build search index.

??? quote "Source"
    ```` {.python  title='mkdocs.contrib.search.SearchPlugin.on_post_build' linenums='95'}
    def on_post_build(self, config: MkDocsConfig, **kwargs) -&gt; None:
        """Build search index."""
        output_base_path = os.path.join(config.site_dir, 'search')
        search_index = self.search_index.generate_search_index()
        json_output_path = os.path.join(output_base_path, 'search_index.json')
        utils.write_file(search_index.encode('utf-8'), json_output_path)

        assert self.config.lang is not None
        if not config.theme.get('search_index_only'):
            # Include language support files in output. Copy them directly
            # so that only the needed files are included.
            files = []
            if len(self.config.lang) &gt; 1 or 'en' not in self.config.lang:
                files.append('lunr.stemmer.support.js')
            if len(self.config.lang) &gt; 1:
                files.append('lunr.multi.js')
            if 'ja' in self.config.lang or 'jp' in self.config.lang:
                files.append('tinyseg.js')
            for lang in self.config.lang:
                if lang != 'en':
                    files.append(f'lunr.{lang}.js')

            for filename in files:
                from_path = os.path.join(base_path, 'lunr-language', filename)
                to_path = os.path.join(output_base_path, filename)
                utils.copy_file(from_path, to_path)

    ````


??? info "Hook info"
    ::: mkdocs.plugins.BasePlugin.on_post_build
        options:
          show_source: False
          show_root_toc_entry: False


</div>
<h2 id="searchplugin">SearchPlugin</h2>
<div class="speech bottom">
<h2 id="on_config"><a href="https://www.mkdocs.org/dev-guide/plugins/#on_config">on_config</a></h2>
<p>Add plugin templates and scripts to config.</p>
<details class="quote">
<summary>Source</summary>
<div class="language-python highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">mkdocs.contrib.search.SearchPlugin.on_config</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-65">65</a></span>
<span class="normal"><a href="#__codelineno-0-66">66</a></span>
<span class="normal"><a href="#__codelineno-0-67">67</a></span>
<span class="normal"><a href="#__codelineno-0-68">68</a></span>
<span class="normal"><a href="#__codelineno-0-69">69</a></span>
<span class="normal"><a href="#__codelineno-0-70">70</a></span>
<span class="normal"><a href="#__codelineno-0-71">71</a></span>
<span class="normal"><a href="#__codelineno-0-72">72</a></span>
<span class="normal"><a href="#__codelineno-0-73">73</a></span>
<span class="normal"><a href="#__codelineno-0-74">74</a></span>
<span class="normal"><a href="#__codelineno-0-75">75</a></span>
<span class="normal"><a href="#__codelineno-0-76">76</a></span>
<span class="normal"><a href="#__codelineno-0-77">77</a></span>
<span class="normal"><a href="#__codelineno-0-78">78</a></span>
<span class="normal"><a href="#__codelineno-0-79">79</a></span>
<span class="normal"><a href="#__codelineno-0-80">80</a></span>
<span class="normal"><a href="#__codelineno-0-81">81</a></span>
<span class="normal"><a href="#__codelineno-0-82">82</a></span>
<span class="normal"><a href="#__codelineno-0-83">83</a></span>
<span class="normal"><a href="#__codelineno-0-84">84</a></span>
<span class="normal"><a href="#__codelineno-0-85">85</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-65"><a id="__codelineno-0-65" name="__codelineno-0-65"></a><span class="k">def</span> <span class="nf">on_config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">:</span> <span class="n">MkDocsConfig</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&amp;</span><span class="n">gt</span><span class="p">;</span> <span class="n">MkDocsConfig</span><span class="p">:</span>
</span><span id="__span-0-66"><a id="__codelineno-0-66" name="__codelineno-0-66"></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;Add plugin templates and scripts to config.&quot;&quot;&quot;</span>
</span><span id="__span-0-67"><a id="__codelineno-0-67" name="__codelineno-0-67"></a>    <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">theme</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;include_search_page&#39;</span><span class="p">):</span>
</span><span id="__span-0-68"><a id="__codelineno-0-68" name="__codelineno-0-68"></a>        <span class="n">config</span><span class="o">.</span><span class="n">theme</span><span class="o">.</span><span class="n">static_templates</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s1">&#39;search.html&#39;</span><span class="p">)</span>
</span><span id="__span-0-69"><a id="__codelineno-0-69" name="__codelineno-0-69"></a>    <span class="k">if</span> <span class="ow">not</span> <span class="n">config</span><span class="o">.</span><span class="n">theme</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;search_index_only&#39;</span><span class="p">):</span>
</span><span id="__span-0-70"><a id="__codelineno-0-70" name="__codelineno-0-70"></a>        <span class="n">path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">base_path</span><span class="p">,</span> <span class="s1">&#39;templates&#39;</span><span class="p">)</span>
</span><span id="__span-0-71"><a id="__codelineno-0-71" name="__codelineno-0-71"></a>        <span class="n">config</span><span class="o">.</span><span class="n">theme</span><span class="o">.</span><span class="n">dirs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
</span><span id="__span-0-72"><a id="__codelineno-0-72" name="__codelineno-0-72"></a>        <span class="k">if</span> <span class="s1">&#39;search/main.js&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">config</span><span class="o">.</span><span class="n">extra_javascript</span><span class="p">:</span>
</span><span id="__span-0-73"><a id="__codelineno-0-73" name="__codelineno-0-73"></a>            <span class="n">config</span><span class="o">.</span><span class="n">extra_javascript</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;search/main.js&#39;</span><span class="p">)</span>  <span class="c1"># type: ignore</span>
</span><span id="__span-0-74"><a id="__codelineno-0-74" name="__codelineno-0-74"></a>    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-0-75"><a id="__codelineno-0-75" name="__codelineno-0-75"></a>        <span class="c1"># lang setting undefined. Set default based on theme locale</span>
</span><span id="__span-0-76"><a id="__codelineno-0-76" name="__codelineno-0-76"></a>        <span class="n">validate</span> <span class="o">=</span> <span class="n">_PluginConfig</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">run_validation</span>
</span><span id="__span-0-77"><a id="__codelineno-0-77" name="__codelineno-0-77"></a>        <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span> <span class="o">=</span> <span class="n">validate</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">theme</span><span class="o">.</span><span class="n">locale</span><span class="o">.</span><span class="n">language</span><span class="p">)</span>
</span><span id="__span-0-78"><a id="__codelineno-0-78" name="__codelineno-0-78"></a>    <span class="c1"># The `python` method of `prebuild_index` is pending deprecation as of version 1.2.</span>
</span><span id="__span-0-79"><a id="__codelineno-0-79" name="__codelineno-0-79"></a>    <span class="c1"># TODO: Raise a deprecation warning in a future release (1.3?).</span>
</span><span id="__span-0-80"><a id="__codelineno-0-80" name="__codelineno-0-80"></a>    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">prebuild_index</span> <span class="o">==</span> <span class="s1">&#39;python&#39;</span><span class="p">:</span>
</span><span id="__span-0-81"><a id="__codelineno-0-81" name="__codelineno-0-81"></a>        <span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span>
</span><span id="__span-0-82"><a id="__codelineno-0-82" name="__codelineno-0-82"></a>            <span class="s2">&quot;The &#39;python&#39; method of the search plugin&#39;s &#39;prebuild_index&#39; config option &quot;</span>
</span><span id="__span-0-83"><a id="__codelineno-0-83" name="__codelineno-0-83"></a>            <span class="s2">&quot;is pending deprecation and will not be supported in a future release.&quot;</span>
</span><span id="__span-0-84"><a id="__codelineno-0-84" name="__codelineno-0-84"></a>        <span class="p">)</span>
</span><span id="__span-0-85"><a id="__codelineno-0-85" name="__codelineno-0-85"></a>    <span class="k">return</span> <span class="n">config</span>
</span></code></pre></div></td></tr></table></div>
</details>
<details class="info">
<summary>Hook info</summary>
<p>::: mkdocs.plugins.BasePlugin.on_config
    options:
      show_source: False
      show_root_toc_entry: False</p>
</details>
</div>
<div class="speech bottom">
<h2 id="on_pre_build"><a href="https://www.mkdocs.org/dev-guide/plugins/#on_pre_build">on_pre_build</a></h2>
<p>Create search index instance for later use.</p>
<details class="quote">
<summary>Source</summary>
<div class="language-python highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">mkdocs.contrib.search.SearchPlugin.on_pre_build</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-1-87">87</a></span>
<span class="normal"><a href="#__codelineno-1-88">88</a></span>
<span class="normal"><a href="#__codelineno-1-89">89</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-1-87"><a id="__codelineno-1-87" name="__codelineno-1-87"></a><span class="k">def</span> <span class="nf">on_pre_build</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">:</span> <span class="n">MkDocsConfig</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&amp;</span><span class="n">gt</span><span class="p">;</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-1-88"><a id="__codelineno-1-88" name="__codelineno-1-88"></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;Create search index instance for later use.&quot;&quot;&quot;</span>
</span><span id="__span-1-89"><a id="__codelineno-1-89" name="__codelineno-1-89"></a>    <span class="bp">self</span><span class="o">.</span><span class="n">search_index</span> <span class="o">=</span> <span class="n">SearchIndex</span><span class="p">(</span><span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
<details class="info">
<summary>Hook info</summary>
<p>::: mkdocs.plugins.BasePlugin.on_pre_build
    options:
      show_source: False
      show_root_toc_entry: False</p>
</details>
</div>
<div class="speech bottom">
<h2 id="on_post_build"><a href="https://www.mkdocs.org/dev-guide/plugins/#on_post_build">on_post_build</a></h2>
<p>Build search index.</p>
<details class="quote">
<summary>Source</summary>
<div class="language-python highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">mkdocs.contrib.search.SearchPlugin.on_post_build</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-2-95"> 95</a></span>
<span class="normal"><a href="#__codelineno-2-96"> 96</a></span>
<span class="normal"><a href="#__codelineno-2-97"> 97</a></span>
<span class="normal"><a href="#__codelineno-2-98"> 98</a></span>
<span class="normal"><a href="#__codelineno-2-99"> 99</a></span>
<span class="normal"><a href="#__codelineno-2-100">100</a></span>
<span class="normal"><a href="#__codelineno-2-101">101</a></span>
<span class="normal"><a href="#__codelineno-2-102">102</a></span>
<span class="normal"><a href="#__codelineno-2-103">103</a></span>
<span class="normal"><a href="#__codelineno-2-104">104</a></span>
<span class="normal"><a href="#__codelineno-2-105">105</a></span>
<span class="normal"><a href="#__codelineno-2-106">106</a></span>
<span class="normal"><a href="#__codelineno-2-107">107</a></span>
<span class="normal"><a href="#__codelineno-2-108">108</a></span>
<span class="normal"><a href="#__codelineno-2-109">109</a></span>
<span class="normal"><a href="#__codelineno-2-110">110</a></span>
<span class="normal"><a href="#__codelineno-2-111">111</a></span>
<span class="normal"><a href="#__codelineno-2-112">112</a></span>
<span class="normal"><a href="#__codelineno-2-113">113</a></span>
<span class="normal"><a href="#__codelineno-2-114">114</a></span>
<span class="normal"><a href="#__codelineno-2-115">115</a></span>
<span class="normal"><a href="#__codelineno-2-116">116</a></span>
<span class="normal"><a href="#__codelineno-2-117">117</a></span>
<span class="normal"><a href="#__codelineno-2-118">118</a></span>
<span class="normal"><a href="#__codelineno-2-119">119</a></span>
<span class="normal"><a href="#__codelineno-2-120">120</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-2-95"><a id="__codelineno-2-95" name="__codelineno-2-95"></a><span class="k">def</span> <span class="nf">on_post_build</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">:</span> <span class="n">MkDocsConfig</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&amp;</span><span class="n">gt</span><span class="p">;</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-2-96"><a id="__codelineno-2-96" name="__codelineno-2-96"></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;Build search index.&quot;&quot;&quot;</span>
</span><span id="__span-2-97"><a id="__codelineno-2-97" name="__codelineno-2-97"></a>    <span class="n">output_base_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">site_dir</span><span class="p">,</span> <span class="s1">&#39;search&#39;</span><span class="p">)</span>
</span><span id="__span-2-98"><a id="__codelineno-2-98" name="__codelineno-2-98"></a>    <span class="n">search_index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">search_index</span><span class="o">.</span><span class="n">generate_search_index</span><span class="p">()</span>
</span><span id="__span-2-99"><a id="__codelineno-2-99" name="__codelineno-2-99"></a>    <span class="n">json_output_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_base_path</span><span class="p">,</span> <span class="s1">&#39;search_index.json&#39;</span><span class="p">)</span>
</span><span id="__span-2-100"><a id="__codelineno-2-100" name="__codelineno-2-100"></a>    <span class="n">utils</span><span class="o">.</span><span class="n">write_file</span><span class="p">(</span><span class="n">search_index</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">),</span> <span class="n">json_output_path</span><span class="p">)</span>
</span><span id="__span-2-101"><a id="__codelineno-2-101" name="__codelineno-2-101"></a>
</span><span id="__span-2-102"><a id="__codelineno-2-102" name="__codelineno-2-102"></a>    <span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
</span><span id="__span-2-103"><a id="__codelineno-2-103" name="__codelineno-2-103"></a>    <span class="k">if</span> <span class="ow">not</span> <span class="n">config</span><span class="o">.</span><span class="n">theme</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;search_index_only&#39;</span><span class="p">):</span>
</span><span id="__span-2-104"><a id="__codelineno-2-104" name="__codelineno-2-104"></a>        <span class="c1"># Include language support files in output. Copy them directly</span>
</span><span id="__span-2-105"><a id="__codelineno-2-105" name="__codelineno-2-105"></a>        <span class="c1"># so that only the needed files are included.</span>
</span><span id="__span-2-106"><a id="__codelineno-2-106" name="__codelineno-2-106"></a>        <span class="n">files</span> <span class="o">=</span> <span class="p">[]</span>
</span><span id="__span-2-107"><a id="__codelineno-2-107" name="__codelineno-2-107"></a>        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="p">)</span> <span class="o">&amp;</span><span class="n">gt</span><span class="p">;</span> <span class="mi">1</span> <span class="ow">or</span> <span class="s1">&#39;en&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="p">:</span>
</span><span id="__span-2-108"><a id="__codelineno-2-108" name="__codelineno-2-108"></a>            <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;lunr.stemmer.support.js&#39;</span><span class="p">)</span>
</span><span id="__span-2-109"><a id="__codelineno-2-109" name="__codelineno-2-109"></a>        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="p">)</span> <span class="o">&amp;</span><span class="n">gt</span><span class="p">;</span> <span class="mi">1</span><span class="p">:</span>
</span><span id="__span-2-110"><a id="__codelineno-2-110" name="__codelineno-2-110"></a>            <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;lunr.multi.js&#39;</span><span class="p">)</span>
</span><span id="__span-2-111"><a id="__codelineno-2-111" name="__codelineno-2-111"></a>        <span class="k">if</span> <span class="s1">&#39;ja&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span> <span class="ow">or</span> <span class="s1">&#39;jp&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="p">:</span>
</span><span id="__span-2-112"><a id="__codelineno-2-112" name="__codelineno-2-112"></a>            <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;tinyseg.js&#39;</span><span class="p">)</span>
</span><span id="__span-2-113"><a id="__codelineno-2-113" name="__codelineno-2-113"></a>        <span class="k">for</span> <span class="n">lang</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="p">:</span>
</span><span id="__span-2-114"><a id="__codelineno-2-114" name="__codelineno-2-114"></a>            <span class="k">if</span> <span class="n">lang</span> <span class="o">!=</span> <span class="s1">&#39;en&#39;</span><span class="p">:</span>
</span><span id="__span-2-115"><a id="__codelineno-2-115" name="__codelineno-2-115"></a>                <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;lunr.</span><span class="si">{</span><span class="n">lang</span><span class="si">}</span><span class="s1">.js&#39;</span><span class="p">)</span>
</span><span id="__span-2-116"><a id="__codelineno-2-116" name="__codelineno-2-116"></a>
</span><span id="__span-2-117"><a id="__codelineno-2-117" name="__codelineno-2-117"></a>        <span class="k">for</span> <span class="n">filename</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
</span><span id="__span-2-118"><a id="__codelineno-2-118" name="__codelineno-2-118"></a>            <span class="n">from_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">base_path</span><span class="p">,</span> <span class="s1">&#39;lunr-language&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
</span><span id="__span-2-119"><a id="__codelineno-2-119" name="__codelineno-2-119"></a>            <span class="n">to_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_base_path</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
</span><span id="__span-2-120"><a id="__codelineno-2-120" name="__codelineno-2-120"></a>            <span class="n">utils</span><span class="o">.</span><span class="n">copy_file</span><span class="p">(</span><span class="n">from_path</span><span class="p">,</span> <span class="n">to_path</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
<details class="info">
<summary>Hook info</summary>
<p>::: mkdocs.plugins.BasePlugin.on_post_build
    options:
      show_source: False
      show_root_toc_entry: False</p>
</details>
</div>
<div class="speech bottom">
<h2 id="on_page_context"><a href="https://www.mkdocs.org/dev-guide/plugins/#on_page_context">on_page_context</a></h2>
<p>Add page to search index.</p>
<details class="quote">
<summary>Source</summary>
<div class="language-python highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">mkdocs.contrib.search.SearchPlugin.on_page_context</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-3-91">91</a></span>
<span class="normal"><a href="#__codelineno-3-92">92</a></span>
<span class="normal"><a href="#__codelineno-3-93">93</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-3-91"><a id="__codelineno-3-91" name="__codelineno-3-91"></a><span class="k">def</span> <span class="nf">on_page_context</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">:</span> <span class="n">TemplateContext</span><span class="p">,</span> <span class="n">page</span><span class="p">:</span> <span class="n">Page</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&amp;</span><span class="n">gt</span><span class="p">;</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-3-92"><a id="__codelineno-3-92" name="__codelineno-3-92"></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;Add page to search index.&quot;&quot;&quot;</span>
</span><span id="__span-3-93"><a id="__codelineno-3-93" name="__codelineno-3-93"></a>    <span class="bp">self</span><span class="o">.</span><span class="n">search_index</span><span class="o">.</span><span class="n">add_entry_from_context</span><span class="p">(</span><span class="n">page</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
<details class="info">
<summary>Hook info</summary>
<p>::: mkdocs.plugins.BasePlugin.on_page_context
    options:
      show_source: False
      show_root_toc_entry: False</p>
</details>
</div>
<div class="speech">
<h2 id="on_post_build_1"><a href="https://www.mkdocs.org/dev-guide/plugins/#on_post_build">on_post_build</a></h2>
<p>Build search index.</p>
<details class="quote">
<summary>Source</summary>
<div class="language-python highlight"><table class="highlighttable"><tr><th colspan="2" class="filename"><span class="filename">mkdocs.contrib.search.SearchPlugin.on_post_build</span></th></tr><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-4-95"> 95</a></span>
<span class="normal"><a href="#__codelineno-4-96"> 96</a></span>
<span class="normal"><a href="#__codelineno-4-97"> 97</a></span>
<span class="normal"><a href="#__codelineno-4-98"> 98</a></span>
<span class="normal"><a href="#__codelineno-4-99"> 99</a></span>
<span class="normal"><a href="#__codelineno-4-100">100</a></span>
<span class="normal"><a href="#__codelineno-4-101">101</a></span>
<span class="normal"><a href="#__codelineno-4-102">102</a></span>
<span class="normal"><a href="#__codelineno-4-103">103</a></span>
<span class="normal"><a href="#__codelineno-4-104">104</a></span>
<span class="normal"><a href="#__codelineno-4-105">105</a></span>
<span class="normal"><a href="#__codelineno-4-106">106</a></span>
<span class="normal"><a href="#__codelineno-4-107">107</a></span>
<span class="normal"><a href="#__codelineno-4-108">108</a></span>
<span class="normal"><a href="#__codelineno-4-109">109</a></span>
<span class="normal"><a href="#__codelineno-4-110">110</a></span>
<span class="normal"><a href="#__codelineno-4-111">111</a></span>
<span class="normal"><a href="#__codelineno-4-112">112</a></span>
<span class="normal"><a href="#__codelineno-4-113">113</a></span>
<span class="normal"><a href="#__codelineno-4-114">114</a></span>
<span class="normal"><a href="#__codelineno-4-115">115</a></span>
<span class="normal"><a href="#__codelineno-4-116">116</a></span>
<span class="normal"><a href="#__codelineno-4-117">117</a></span>
<span class="normal"><a href="#__codelineno-4-118">118</a></span>
<span class="normal"><a href="#__codelineno-4-119">119</a></span>
<span class="normal"><a href="#__codelineno-4-120">120</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-4-95"><a id="__codelineno-4-95" name="__codelineno-4-95"></a><span class="k">def</span> <span class="nf">on_post_build</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">:</span> <span class="n">MkDocsConfig</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&amp;</span><span class="n">gt</span><span class="p">;</span> <span class="kc">None</span><span class="p">:</span>
</span><span id="__span-4-96"><a id="__codelineno-4-96" name="__codelineno-4-96"></a><span class="w">    </span><span class="sd">&quot;&quot;&quot;Build search index.&quot;&quot;&quot;</span>
</span><span id="__span-4-97"><a id="__codelineno-4-97" name="__codelineno-4-97"></a>    <span class="n">output_base_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">site_dir</span><span class="p">,</span> <span class="s1">&#39;search&#39;</span><span class="p">)</span>
</span><span id="__span-4-98"><a id="__codelineno-4-98" name="__codelineno-4-98"></a>    <span class="n">search_index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">search_index</span><span class="o">.</span><span class="n">generate_search_index</span><span class="p">()</span>
</span><span id="__span-4-99"><a id="__codelineno-4-99" name="__codelineno-4-99"></a>    <span class="n">json_output_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_base_path</span><span class="p">,</span> <span class="s1">&#39;search_index.json&#39;</span><span class="p">)</span>
</span><span id="__span-4-100"><a id="__codelineno-4-100" name="__codelineno-4-100"></a>    <span class="n">utils</span><span class="o">.</span><span class="n">write_file</span><span class="p">(</span><span class="n">search_index</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">),</span> <span class="n">json_output_path</span><span class="p">)</span>
</span><span id="__span-4-101"><a id="__codelineno-4-101" name="__codelineno-4-101"></a>
</span><span id="__span-4-102"><a id="__codelineno-4-102" name="__codelineno-4-102"></a>    <span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
</span><span id="__span-4-103"><a id="__codelineno-4-103" name="__codelineno-4-103"></a>    <span class="k">if</span> <span class="ow">not</span> <span class="n">config</span><span class="o">.</span><span class="n">theme</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;search_index_only&#39;</span><span class="p">):</span>
</span><span id="__span-4-104"><a id="__codelineno-4-104" name="__codelineno-4-104"></a>        <span class="c1"># Include language support files in output. Copy them directly</span>
</span><span id="__span-4-105"><a id="__codelineno-4-105" name="__codelineno-4-105"></a>        <span class="c1"># so that only the needed files are included.</span>
</span><span id="__span-4-106"><a id="__codelineno-4-106" name="__codelineno-4-106"></a>        <span class="n">files</span> <span class="o">=</span> <span class="p">[]</span>
</span><span id="__span-4-107"><a id="__codelineno-4-107" name="__codelineno-4-107"></a>        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="p">)</span> <span class="o">&amp;</span><span class="n">gt</span><span class="p">;</span> <span class="mi">1</span> <span class="ow">or</span> <span class="s1">&#39;en&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="p">:</span>
</span><span id="__span-4-108"><a id="__codelineno-4-108" name="__codelineno-4-108"></a>            <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;lunr.stemmer.support.js&#39;</span><span class="p">)</span>
</span><span id="__span-4-109"><a id="__codelineno-4-109" name="__codelineno-4-109"></a>        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="p">)</span> <span class="o">&amp;</span><span class="n">gt</span><span class="p">;</span> <span class="mi">1</span><span class="p">:</span>
</span><span id="__span-4-110"><a id="__codelineno-4-110" name="__codelineno-4-110"></a>            <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;lunr.multi.js&#39;</span><span class="p">)</span>
</span><span id="__span-4-111"><a id="__codelineno-4-111" name="__codelineno-4-111"></a>        <span class="k">if</span> <span class="s1">&#39;ja&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span> <span class="ow">or</span> <span class="s1">&#39;jp&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="p">:</span>
</span><span id="__span-4-112"><a id="__codelineno-4-112" name="__codelineno-4-112"></a>            <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;tinyseg.js&#39;</span><span class="p">)</span>
</span><span id="__span-4-113"><a id="__codelineno-4-113" name="__codelineno-4-113"></a>        <span class="k">for</span> <span class="n">lang</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="p">:</span>
</span><span id="__span-4-114"><a id="__codelineno-4-114" name="__codelineno-4-114"></a>            <span class="k">if</span> <span class="n">lang</span> <span class="o">!=</span> <span class="s1">&#39;en&#39;</span><span class="p">:</span>
</span><span id="__span-4-115"><a id="__codelineno-4-115" name="__codelineno-4-115"></a>                <span class="n">files</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;lunr.</span><span class="si">{</span><span class="n">lang</span><span class="si">}</span><span class="s1">.js&#39;</span><span class="p">)</span>
</span><span id="__span-4-116"><a id="__codelineno-4-116" name="__codelineno-4-116"></a>
</span><span id="__span-4-117"><a id="__codelineno-4-117" name="__codelineno-4-117"></a>        <span class="k">for</span> <span class="n">filename</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
</span><span id="__span-4-118"><a id="__codelineno-4-118" name="__codelineno-4-118"></a>            <span class="n">from_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">base_path</span><span class="p">,</span> <span class="s1">&#39;lunr-language&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
</span><span id="__span-4-119"><a id="__codelineno-4-119" name="__codelineno-4-119"></a>            <span class="n">to_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output_base_path</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
</span><span id="__span-4-120"><a id="__codelineno-4-120" name="__codelineno-4-120"></a>            <span class="n">utils</span><span class="o">.</span><span class="n">copy_file</span><span class="p">(</span><span class="n">from_path</span><span class="p">,</span> <span class="n">to_path</span><span class="p">)</span>
</span></code></pre></div></td></tr></table></div>
</details>
<details class="info">
<summary>Hook info</summary>
<p>::: mkdocs.plugins.BasePlugin.on_post_build
    options:
      show_source: False
      show_root_toc_entry: False</p>
</details>
</div>
MkPluginFlow
├── MkLink('https://www.mkdocs.org/dev-guide/plugins/#on_post_build', 'on_post_build')
├── MkHeader('[on_post_build](https://www.mkdocs.org/dev-guide/plugins/#on_post_build)')
├── MkAdmonition([list([...])], typ='quote', title='Source', collapsible=True)
│   ╰── MkCode('def on_post_build(self, config: MkDocsConfig, *...           utils.copy_file(from_path, to_path)\n', title='mkdocs.contrib.search.SearchPlugin.on_post_build', linenums=95)
│       ╰── MkText('def on_post_build(self, config: MkDocsConfig, **kwargs) -> None:\n    """Build search index."""\n    output_base_path = os.path.join(config.site_dir, \'search\')\n    search_index = self.search_index.generate_search_index()\n    json_output_path = os.path.join(output_base_path, \'search_index.json\')\n    utils.write_file(search_index.encode(\'utf-8\'), json_output_path)\n\n    assert self.config.lang is not None\n    if not config.theme.get(\'search_index_only\'):\n        # Include language support files in output. Copy them directly\n        # so that only the needed files are included.\n        files = []\n        if len(self.config.lang) > 1 or \'en\' not in self.config.lang:\n            files.append(\'lunr.stemmer.support.js\')\n        if len(self.config.lang) > 1:\n            files.append(\'lunr.multi.js\')\n        if \'ja\' in self.config.lang or \'jp\' in self.config.lang:\n            files.append(\'tinyseg.js\')\n        for lang in self.config.lang:\n            if lang != \'en\':\n                files.append(f\'lunr.{lang}.js\')\n\n        for filename in files:\n            from_path = os.path.join(base_path, \'lunr-language\', filename)\n            to_path = os.path.join(output_base_path, filename)\n            utils.copy_file(from_path, to_path)\n')
├── MkAdmonition([list([...])], title='Hook info', collapsible=True)
│   ╰── MkDocStrings(obj='mkdocs.plugins.BasePlugin.on_post_build', show_source=False, show_root_toc_entry=False)
╰── MkSpeechBubble('## [on_post_build](https://www.mkdocs.org/dev-g... False\n          show_root_toc_entry: False\n\n', arrow=None)
    ╰── MkText('## [on_post_build](https://www.mkdocs.org/dev-guide/plugins/#on_post_build)\n\nBuild search index.\n\n??? quote "Source"\n    ```` {.python  title=\'mkdocs.contrib.search.SearchPlugin.on_post_build\' linenums=\'95\'}\n    def on_post_build(self, config: MkDocsConfig, **kwargs) -> None:\n        """Build search index."""\n        output_base_path = os.path.join(config.site_dir, \'search\')\n        search_index = self.search_index.generate_search_index()\n        json_output_path = os.path.join(output_base_path, \'search_index.json\')\n        utils.write_file(search_index.encode(\'utf-8\'), json_output_path)\n\n        assert self.config.lang is not None\n        if not config.theme.get(\'search_index_only\'):\n            # Include language support files in output. Copy them directly\n            # so that only the needed files are included.\n            files = []\n            if len(self.config.lang) > 1 or \'en\' not in self.config.lang:\n                files.append(\'lunr.stemmer.support.js\')\n            if len(self.config.lang) > 1:\n                files.append(\'lunr.multi.js\')\n            if \'ja\' in self.config.lang or \'jp\' in self.config.lang:\n                files.append(\'tinyseg.js\')\n            for lang in self.config.lang:\n                if lang != \'en\':\n                    files.append(f\'lunr.{lang}.js\')\n\n            for filename in files:\n                from_path = os.path.join(base_path, \'lunr-language\', filename)\n                to_path = os.path.join(output_base_path, filename)\n                utils.copy_file(from_path, to_path)\n\n    ````\n\n\n??? info "Hook info"\n    ::: mkdocs.plugins.BasePlugin.on_post_build\n        options:\n          show_source: False\n          show_root_toc_entry: False\n\n')

Bases: MkTemplate

__init__

__init__(plugin: type[BasePlugin] | str | None = None, **kwargs: Any)

Parameters:

Name Type Description Default
plugin type[BasePlugin] | str | None

MkDocs plugin

None
kwargs Any

Keyword arguments passed to parent

{}
graph TD
  94721311800096["mkpluginflow.MkPluginFlow"]
  94721308869584["mktemplate.MkTemplate"]
  94721311697232["mkcontainer.MkContainer"]
  94721308848336["mknode.MkNode"]
  94721311766592["node.Node"]
  140564252373184["builtins.object"]
  94721308869584 --> 94721311800096
  94721311697232 --> 94721308869584
  94721308848336 --> 94721311697232
  94721311766592 --> 94721308848336
  140564252373184 --> 94721311766592
/home/runner/work/mknodes/mknodes/mknodes/templatenodes/mkpluginflow/metadata.toml
[metadata]
name = "MkPluginFlow"
icon = "mdi:dev-to"
status = "new"
group = "documentation"
virtual_children = true

[examples.regular]
title = "Regular"
jinja = """
{{ "mkdocs.contrib.search.SearchPlugin" | to_class | MkPluginFlow }}
"""

[fragments]
bubble = """
{{ node.event_plugin.help_link.format(event=fn.__name__) | MkLink(fn.__name__) | MkHeader }}

{{ fn | get_doc }}

{{ mk.MkCode.for_object(fn) | MkAdmonition(collapsible=True, typ="quote", title="Source")}}

{{ node.event_plugin.hook_fn_path.format(event=fn.__name__) | MkDocStrings(show_source=False, show_root_toc_entry=False) | MkAdmonition(collapsible=True, title="Hook info")}}
"""

[output.markdown]
template = """
{% for plg in node.plugins %}
{{ plg.__name__ | MkHeader }}
{% for event in node.hooks_for_plugin(plg) %}
{% if plg | hasattr(event) %}
{{ "fragments/bubble" | render_template(fn=(plg | attr(event))) | MkSpeechBubble(arrow=None if loop.last else "bottom") }}
{% endif %}
{% endfor %}
{% endfor %}
"""
mknodes.templatenodes.mkpluginflow.MkPluginFlow
class MkPluginFlow(mktemplate.MkTemplate):
    """Node showing info about the different stages of an MkDocs plugin."""

    ICON = "material/dev-to"
    STATUS = "new"

    def __init__(
        self,
        plugin: type[plugins.BasePlugin] | str | None = None,
        **kwargs: Any,
    ):
        """Constructor.

        Args:
            plugin: MkDocs plugin
            kwargs: Keyword arguments passed to parent
        """
        super().__init__("output/markdown/template", **kwargs)
        self._plugin = plugin

    @property
    def plugins(self):
        match self._plugin:
            case None:
                ep_group = self.event_plugin.entry_point_group
                eps = self.ctx.metadata.entry_points.get_group(ep_group)
                return [i.load() for i in eps]
            case type():
                return [self._plugin]
            case str():
                return [classhelpers.to_class(self._plugin)]
            case _:
                raise TypeError(self._plugin)

    @property
    def event_plugin(self):
        return eventplugins.mkdocs_plugin

    def hooks_for_plugin(self, plugin):
        return [e for e in self.event_plugin.flow if hasattr(plugin, e)]