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