|
2 | 2 | import os |
3 | 3 | import shutil |
4 | 4 | import sys |
| 5 | +from html import escape |
5 | 6 | from typing import BinaryIO, cast |
6 | 7 | from importlib.resources import files |
7 | 8 | from pathlib import Path |
@@ -137,6 +138,7 @@ def build_index(): |
137 | 138 |
|
138 | 139 | template_path = Path(__file__).parent.joinpath("index_template.html") |
139 | 140 | fill_data_into_html(template_path, readers_table, profiles_table) |
| 141 | + build_html_links_page(base_path) |
140 | 142 |
|
141 | 143 |
|
142 | 144 | def readers_dict_to_grid_config(): |
@@ -256,6 +258,75 @@ def fill_data_into_html(html_file: Path, readers_table, profiles_table): |
256 | 258 | with open(index_path, "w") as file: |
257 | 259 | file.write(html_content) |
258 | 260 |
|
| 261 | + |
| 262 | +def build_html_links_page(base_path: Path): |
| 263 | + docs_dir = Path(base_path, "docs") |
| 264 | + atch_dir = docs_dir / "atch" |
| 265 | + links_page_name = "all-pages.html" |
| 266 | + |
| 267 | + # Keep these customizable for future filtering needs. |
| 268 | + additional_folder_blacklist = {".git", "__pycache__"} |
| 269 | + extension_blacklist = {".md", ".png", ".jpg", ".jpeg", ".gif", ".css", ".js", ".json", ".txt", ".py", ".exe", ".sh"} |
| 270 | + folder_blacklist = {"server", *additional_folder_blacklist} |
| 271 | + |
| 272 | + root_links = [] |
| 273 | + atch_links = [] |
| 274 | + |
| 275 | + for page in sorted(docs_dir.iterdir()): |
| 276 | + if not page.is_file(): |
| 277 | + continue |
| 278 | + if page.name == links_page_name or page.suffix.lower() in extension_blacklist: |
| 279 | + continue |
| 280 | + root_links.append(page.relative_to(docs_dir).as_posix()) |
| 281 | + |
| 282 | + if atch_dir.exists(): |
| 283 | + for page in sorted(atch_dir.rglob("*")): |
| 284 | + if not page.is_file() or page.suffix.lower() in extension_blacklist: |
| 285 | + continue |
| 286 | + rel_to_atch = page.relative_to(atch_dir) |
| 287 | + if any(part in folder_blacklist for part in rel_to_atch.parts[:-1]): |
| 288 | + continue |
| 289 | + atch_links.append(page.relative_to(docs_dir).as_posix()) |
| 290 | + |
| 291 | + def render_links(paths): |
| 292 | + if not paths: |
| 293 | + return "<li>No matching files found.</li>" |
| 294 | + return "\n".join( |
| 295 | + f' <li><a href="{escape(path)}">{escape(path)}</a></li>' for path in paths |
| 296 | + ) |
| 297 | + |
| 298 | + html_content = f"""<!doctype html> |
| 299 | +<html lang="en"> |
| 300 | + <head> |
| 301 | + <meta charset="utf-8" /> |
| 302 | + <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 303 | + <title>All Pages</title> |
| 304 | + <link rel="stylesheet" href="global.css" /> |
| 305 | + </head> |
| 306 | + <body> |
| 307 | + <header> |
| 308 | + <h1>All Pages</h1> |
| 309 | + <nav> |
| 310 | + <a href="index.html">Back</a> |
| 311 | + </nav> |
| 312 | + </header> |
| 313 | + <main> |
| 314 | + <h2>docs root</h2> |
| 315 | + <ul> |
| 316 | +{render_links(root_links)} |
| 317 | + </ul> |
| 318 | + <h2>docs/atch (without docs/atch/server)</h2> |
| 319 | + <ul> |
| 320 | +{render_links(atch_links)} |
| 321 | + </ul> |
| 322 | + </main> |
| 323 | + </body> |
| 324 | +</html> |
| 325 | +""" |
| 326 | + |
| 327 | + with open(docs_dir / links_page_name, "w") as file: |
| 328 | + file.write(html_content) |
| 329 | + |
259 | 330 | def validate_profiles(): |
260 | 331 | profile_dir = Path(__file__).parent.parent.joinpath('profiles/public') |
261 | 332 | for profile in profile_dir.glob("*.json"): |
|
0 commit comments