mkdocs cli
This commit is contained in:
@@ -1,24 +1,34 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List
|
||||
from pathlib import Path
|
||||
from typing import List, Dict, Any
|
||||
|
||||
from docforge.nav.resolver import ResolvedNav
|
||||
|
||||
|
||||
class MkDocsNavEmitter:
|
||||
"""Emit MkDocs-compatible nav structure."""
|
||||
"""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[Dict[str, str]] = []
|
||||
for path in paths:
|
||||
title = path.stem.replace("_", " ").title()
|
||||
entries.append({title: path.as_posix()})
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user