@@ -36,6 +36,54 @@ def __init__(self, template_dir: Optional[Path] = None):
3636 self .styles = self ._load_template ("styles.css" )
3737 self .app_script = self ._load_template ("app.js" )
3838
39+ def load_module_tree (self , docs_dir : Path ) -> Dict [str , Any ]:
40+ """
41+ Load module tree from documentation directory.
42+
43+ Args:
44+ docs_dir: Documentation directory path
45+
46+ Returns:
47+ Module tree structure
48+ """
49+ module_tree_path = docs_dir / "module_tree.json"
50+ if not module_tree_path .exists ():
51+ # Fallback to a simple structure
52+ return {
53+ "Overview" : {
54+ "description" : "Repository overview" ,
55+ "components" : [],
56+ "children" : {}
57+ }
58+ }
59+
60+ try :
61+ content = safe_read (module_tree_path )
62+ return json .loads (content )
63+ except Exception as e :
64+ raise FileSystemError (f"Failed to load module tree: { e } " )
65+
66+ def load_metadata (self , docs_dir : Path ) -> Optional [Dict [str , Any ]]:
67+ """
68+ Load metadata from documentation directory.
69+
70+ Args:
71+ docs_dir: Documentation directory path
72+
73+ Returns:
74+ Metadata dictionary or None if not found
75+ """
76+ metadata_path = docs_dir / "metadata.json"
77+ if not metadata_path .exists ():
78+ return None
79+
80+ try :
81+ content = safe_read (metadata_path )
82+ return json .loads (content )
83+ except Exception :
84+ # Non-critical, return None
85+ return None
86+
3987 def _load_template (self , filename : str ) -> str :
4088 """
4189 Load a template file.
@@ -59,22 +107,44 @@ def generate(
59107 self ,
60108 output_path : Path ,
61109 title : str ,
62- module_tree : Dict [str , Any ],
110+ module_tree : Optional [ Dict [str , Any ]] = None ,
63111 repository_url : Optional [str ] = None ,
64112 github_pages_url : Optional [str ] = None ,
65- config : Optional [Dict [str , Any ]] = None
113+ config : Optional [Dict [str , Any ]] = None ,
114+ docs_dir : Optional [Path ] = None ,
115+ metadata : Optional [Dict [str , Any ]] = None
66116 ):
67117 """
68118 Generate HTML documentation viewer.
69119
70120 Args:
71121 output_path: Output file path (index.html)
72122 title: Documentation title
73- module_tree: Module tree structure
123+ module_tree: Module tree structure (auto-loaded from docs_dir if not provided)
74124 repository_url: GitHub repository URL
75125 github_pages_url: Expected GitHub Pages URL
76126 config: Additional configuration
127+ docs_dir: Documentation directory (for auto-loading module_tree and metadata)
128+ metadata: Metadata dictionary (auto-loaded from docs_dir if not provided)
77129 """
130+ # Auto-load module tree if docs_dir provided
131+ if docs_dir and module_tree is None :
132+ module_tree = self .load_module_tree (docs_dir )
133+
134+ # Auto-load metadata if docs_dir provided
135+ if docs_dir and metadata is None :
136+ metadata = self .load_metadata (docs_dir )
137+
138+ # Ensure module_tree exists
139+ if module_tree is None :
140+ module_tree = {
141+ "Overview" : {
142+ "description" : "Repository overview" ,
143+ "components" : [],
144+ "children" : {}
145+ }
146+ }
147+
78148 # Build configuration
79149 full_config = {
80150 "title" : title ,
@@ -104,6 +174,10 @@ def generate(
104174 }
105175 }
106176
177+ # Add metadata if available
178+ if metadata :
179+ full_config ["metadata" ] = metadata
180+
107181 if config :
108182 full_config .update (config )
109183
0 commit comments