diff --git a/move_html_to_dir b/move_html_to_dir
index 3e8298e..3ccd8b7 100755
--- a/move_html_to_dir
+++ b/move_html_to_dir
@@ -2,6 +2,7 @@
"""
Rename files like `foo/bar.html` to `foo/bar/index.html` for prettier URLs.
"""
+import json
import re
import sys
from pathlib import Path
@@ -140,6 +141,23 @@ def replace_links(path: Path, replacements: Dict[str, str]):
f.write(contents)
+def fix_search_links(path: Path):
+ """Rename search links to remove the ".html" suffix."""
+ with (path / "searchindex.json").open() as infile:
+ index = json.load(infile)
+
+ doc_urls = [url.replace(".html", "/") for url in index["doc_urls"]]
+ index["doc_urls"] = doc_urls
+
+ index_json = json.dumps(index).strip()
+
+ with (path / "searchindex.json").open("w") as outfile:
+ outfile.write(index_json)
+
+ with (path / "searchindex.js").open("w") as outfile:
+ outfile.write(f"Object.assign(window.search, {index_json});")
+
+
def main(path: Path):
path = path.resolve()
convert_relative_to_absolute(path)
@@ -166,6 +184,9 @@ def main(path: Path):
replace_links(path, replacements)
+ print("Rewriting search links...")
+ fix_search_links(path)
+
if __name__ == "__main__":
main(Path(sys.argv[1]))