| Total Complexity | 4 | 
| Total Lines | 29 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | from collections.abc import Mapping | ||
| 2 | from pathlib import Path | ||
| 3 | |||
| 4 | from starlette.routing import Mount, Route | ||
| 5 | from starlette.staticfiles import StaticFiles | ||
| 6 | |||
| 7 | from ..web import paths_mapping | ||
| 8 | from .views import favicon_route | ||
| 9 | |||
| 10 | |||
| 11 | def _mount_static_files(named_paths: Mapping[str, Path]) -> list[Mount]: | ||
| 12 | mounts = [] | ||
| 13 | for name, path in named_paths.items(): | ||
| 14 |         if not name.startswith('__'): | ||
| 15 | index_file = path / 'index.html' | ||
| 16 | static_files = StaticFiles(directory=path, html=index_file.exists(), check_dir=True) | ||
| 17 |             mount = Mount(path=f"/{name}", app=static_files, name=name) | ||
| 18 | mounts.append(mount) | ||
| 19 | return mounts | ||
| 20 | |||
| 21 | |||
| 22 | def routes(): | ||
| 23 | route_list: list[Mount | Route] = _mount_static_files(paths_mapping) | ||
| 24 | route_list.append(favicon_route()) | ||
| 25 | return route_list | ||
| 26 | |||
| 27 | |||
| 28 | __all__ = ('routes',) | ||
| 29 |