Repository: hikari-py/hikari
Issue: Broken hyperlinks on some search results.

### Steps to reproduce
<!--
Steps to reproduce the bug. This can also be a code snippet.
Make sure you have removed your bot token (if visible).
-->

1. https://hikari-py.github.io/hikari/hikari/search.html
2. Search for a term such as permissions
3. See how most of the results point to index.html, where the item selected is not documented.

### Expected Result
<!--
What should have happened if the bug wasn't there?
Make sure you have removed your bot token (if visible).
-->

The hyperlinks redirect to an actually documented endpoint.

### Actual Result
<!-- What happened exactly? If you have a traceback, please provide all of it. -->

The hyperlinks point to an undocumented area on index.


### Checklist
<!-- Make sure to tick all the following boxes by putting an `x` in between (like this `[x]`) -->
- [x] I have made sure to remove ANY sensitive information (bot token, passwords,
      credentials, personal details, etc).
- [x] I have searched the issue tracker and have made sure it's not a duplicate.
      If it is a follow up of another issue, I have specified it.


Changed files:
docs/patched_pdoc.py

diff --git a/docs/patched_pdoc.py b/docs/patched_pdoc.py
index 66ed1e80..b0e5f147 100644
--- a/docs/patched_pdoc.py
+++ b/docs/patched_pdoc.py
@@ -1,7 +1,77 @@
 # -*- coding: utf-8 -*-
 def main():
+    import json
+    import os.path as path
+    import re
+    from functools import lru_cache
+
+    import pdoc
     from pdoc import cli
 
+    # We don't document stuff on the index of the documentation, but pdoc doesn't know that,
+    # so we have to patch the function that generates the index.
+    def _patched_generate_lunr_search(top_module, index_docstrings, template_config):
+        def trim_docstring(docstring):
+            return re.sub(
+                r"""
+                \\s+|                   # whitespace sequences
+                \\s+[-=~]{3,}\\s+|       # title underlines
+                ^[ \\t]*[`~]{3,}\\w*$|   # code blocks
+                \\s*[`#*]+\\s*|          # common markdown chars
+                \\s*([^\\w\\d_>])\\1\\s*|   # sequences of punct of the same kind
+                \\s*</?\\w*[^>]*>\\s*     # simple HTML tags
+            """,
+                " ",
+                docstring,
+                flags=re.VERBOSE | re.MULTILINE,
+            )
+
+        def recursive_add_to_index(dobj):
+            url = to_url_id(dobj.module)
+            if url != 0:  # 0 is index.html
+                info = {
+                    "ref": dobj.refname,
+                    "url": url,
+                }
+                if index_docstrings:
+                    info["doc"] = trim_docstring(dobj.docstring)
+                if isinstance(dobj, pdoc.Function):
+                    info["func"] = 1
+
+                index.append(info)
+
+            for member_dobj in getattr(dobj, "doc", {}).values():
+                recursive_add_to_index(member_dobj)
+
+        @lru_cache()
+        def to_url_id(module):
+            url = module.url()
+            if top_module.is_package:  # Reference from subfolder if its a package
+                _, url = url.split("/", maxsplit=1)
+            if url not in url_cache:
+                url_cache[url] = len(url_cache)
+            return url_cache[url]
+
+        index = []
+        url_cache = {}
+        recursive_add_to_index(top_module)
+        urls = [i[0] for i in sorted(url_cache.items(), key=lambda i: i[1])]
+
+        # If top module is a package, output the index in its subfolder, else, in the output dir
+        main_path = path.join(cli.args.output_dir, *top_module.name.split(".") if top_module.is_package else "")
+        with cli._open_write_file(path.join(main_path, "index.js")) as f:
+            f.write("URLS=")
+            json.dump(urls, f, indent=0, separators=(",", ":"))
+            f.write(";\\nINDEX=")
+            json.dump(index, f, indent=0, separators=(",", ":"))
+
+        # Generate search.html
+        with cli._open_write_file(path.join(main_path, "search.html")) as f:
+            rendered_template = pdoc._render_template("/search.mako", module=top_module, **template_config)
+            f.write(rendered_template)
+
+    cli._generate_lunr_search = _patched_generate_lunr_search
+
     cli.main()