33 lines
949 B
Python
33 lines
949 B
Python
from pathlib import Path
|
|
from typing import List, Dict, Any
|
|
|
|
from docforge.nav.resolver import ResolvedNav
|
|
|
|
|
|
class MkDocsNavEmitter:
|
|
"""Emit MkDocs-compatible nav structures."""
|
|
|
|
def emit(self, nav: ResolvedNav) -> List[Dict[str, Any]]:
|
|
result: List[Dict[str, Any]] = []
|
|
|
|
# Home entry (semantic path)
|
|
if nav.home:
|
|
result.append({"Home": nav.home})
|
|
|
|
# Group entries
|
|
for group, paths in nav.groups.items():
|
|
entries: List[str] = []
|
|
for p in paths:
|
|
# Convert filesystem path back to docs-relative path
|
|
entries.append(self._to_relative(p))
|
|
result.append({group: entries})
|
|
|
|
return result
|
|
|
|
def _to_relative(self, path: Path) -> str:
|
|
"""
|
|
Convert a filesystem path to a docs-relative path.
|
|
"""
|
|
# Normalize to POSIX-style for MkDocs
|
|
return path.as_posix().split("/docs/", 1)[-1]
|