(output_dir: Path, module: ModuleDoc, position: int)
| 397 | |
| 398 | |
| 399 | def _write_module(output_dir: Path, module: ModuleDoc, position: int) -> None: |
| 400 | lines = [ |
| 401 | frontmatter(module.title, module.description, position), |
| 402 | f"Generated from `{display_path(module.source, resolve=True)}`.\n\n", |
| 403 | f"Import from `{module.import_path}`.\n\n", |
| 404 | ] |
| 405 | if module.description: |
| 406 | lines.append(f"{_escape_text(module.description)}\n\n") |
| 407 | |
| 408 | name_counts: dict[str, int] = {} |
| 409 | for item in module.items: |
| 410 | name_counts[item.name] = name_counts.get(item.name, 0) + 1 |
| 411 | |
| 412 | for kind in SECTION_ORDER: |
| 413 | items = [item for item in module.items if item.kind == kind] |
| 414 | if not items: |
| 415 | continue |
| 416 | lines.append(f"## {SECTION_TITLES[kind]}\n\n") |
| 417 | for item in items: |
| 418 | _write_item(lines, item, disambiguate=name_counts[item.name] > 1) |
| 419 | |
| 420 | if module.reexports: |
| 421 | lines.append("## Re-exports\n\n") |
| 422 | for name in module.reexports: |
| 423 | lines.append(f"- `{name}`\n") |
| 424 | lines.append("\n") |
| 425 | |
| 426 | (output_dir / f"{_slug(module.import_path)}.mdx").write_text("".join(lines), encoding="utf-8") |
| 427 | |
| 428 | |
| 429 | def generate(package_root: Path, output_dir: Path) -> int: |
no test coverage detected