This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
"""
|
||||
This module provides the MkDocsNavEmitter, which converts a ResolvedNav instance
|
||||
into the specific YAML-ready list structure expected by the MkDocs 'nav'
|
||||
configuration.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import List, Dict, Any
|
||||
|
||||
@@ -5,9 +11,21 @@ from docforge.nav.resolver import ResolvedNav
|
||||
|
||||
|
||||
class MkDocsNavEmitter:
|
||||
"""Emit MkDocs-compatible nav structures."""
|
||||
"""
|
||||
Emitter responsible for transforming a ResolvedNav into an MkDocs-compatible
|
||||
navigation structure.
|
||||
"""
|
||||
|
||||
def emit(self, nav: ResolvedNav) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Generate a list of navigation entries for mkdocs.yml.
|
||||
|
||||
Args:
|
||||
nav: The resolved navigation data.
|
||||
|
||||
Returns:
|
||||
A list of dictionary mappings representing the MkDocs navigation.
|
||||
"""
|
||||
result: List[Dict[str, Any]] = []
|
||||
|
||||
# Home entry (semantic path)
|
||||
@@ -27,7 +45,16 @@ class MkDocsNavEmitter:
|
||||
|
||||
def _to_relative(self, path: Path, docs_root: Path | None) -> str:
|
||||
"""
|
||||
Convert a filesystem path to a docs-relative path.
|
||||
Convert a filesystem path to a path relative to the documentation root.
|
||||
This handles both absolute and relative filesystem paths, ensuring the
|
||||
output is compatible with MkDocs navigation requirements.
|
||||
|
||||
Args:
|
||||
path: The path to convert.
|
||||
docs_root: The root directory for documentation.
|
||||
|
||||
Returns:
|
||||
A string representing the relative POSIX-style path.
|
||||
"""
|
||||
if docs_root and path.is_absolute():
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user