search.py 559 B

1234567891011121314151617181920
  1. import json
  2. from pathlib import Path
  3. from . import registry
  4. PATH = Path(__file__).parent.parent / 'static' / 'search_index.json'
  5. def build_search_index() -> None:
  6. """Build search index."""
  7. index = [
  8. {
  9. 'title': f'{documentation.title.replace("*", "")}: {part.title}',
  10. 'content': part.description,
  11. 'url': f'{documentation.route}#{part.link_target}',
  12. }
  13. for documentation in registry.registry.values()
  14. for part in documentation
  15. ]
  16. PATH.write_text(json.dumps(index, indent=2))