@@ -31,8 +31,8 @@ def generate_schema_docs(src_dir, docs_dir):
3131 for yaml_file in yaml_files :
3232 generate_single_doc (yaml_file , src_path , docs_path )
3333
34- # Generate index file
35- generate_index (yaml_files , src_path , docs_path )
34+ # Generate hierarchical index files
35+ generate_hierarchical_indices (yaml_files , src_path , docs_path )
3636
3737
3838def generate_single_doc (yaml_file , src_path , docs_path ):
@@ -195,6 +195,139 @@ def generate_property_doc(prop_name, prop_def):
195195 return content
196196
197197
198+ def generate_hierarchical_indices (yaml_files , src_path , docs_path ):
199+ """Generate hierarchical index files for all directories containing schemas."""
200+ # Get all unique directories that contain schema files
201+ directories = set ()
202+ schemas_by_dir = {}
203+
204+ for yaml_file in yaml_files :
205+ rel_path = yaml_file .relative_to (src_path )
206+ dir_path = rel_path .parent
207+
208+ # Add this directory and all parent directories
209+ current_dir = dir_path
210+ while True :
211+ directories .add (current_dir )
212+ if current_dir == Path ('.' ):
213+ break
214+ current_dir = current_dir .parent
215+
216+ # Group schemas by their immediate directory
217+ dir_key = str (dir_path ) if dir_path != Path ('.' ) else 'root'
218+ if dir_key not in schemas_by_dir :
219+ schemas_by_dir [dir_key ] = []
220+ schemas_by_dir [dir_key ].append (rel_path )
221+
222+ # Generate index file for each directory
223+ for directory in directories :
224+ generate_directory_index (directory , schemas_by_dir , src_path , docs_path , directories )
225+
226+
227+ def generate_directory_index (directory , schemas_by_dir , src_path , docs_path , all_directories ):
228+ """Generate an index file for a specific directory."""
229+ # Determine the index file path
230+ if directory == Path ('.' ):
231+ index_file = docs_path / "index.md"
232+ dir_title = "Schema Documentation"
233+ dir_key = 'root'
234+ else :
235+ index_file = docs_path / directory / "index.md"
236+ dir_title = f"Schema Documentation - { directory .name } "
237+ dir_key = str (directory )
238+
239+ # Ensure directory exists
240+ index_file .parent .mkdir (parents = True , exist_ok = True )
241+
242+ # Get parent directory for navigation
243+ parent_dir = directory .parent if directory != Path ('.' ) else None
244+ parent_link = ""
245+ if parent_dir is not None :
246+ if parent_dir == Path ('.' ):
247+ parent_link = "[↑ Parent Directory](../index.md)"
248+ else :
249+ # Calculate relative path to parent index
250+ depth = len (directory .parts )
251+ parent_path = "../" * depth + str (parent_dir ) + "/index.md"
252+ parent_link = f"[↑ Parent Directory]({ parent_path } )"
253+
254+ # Start building content
255+ content = f"""---
256+ title: "{ dir_title } "
257+ description: "Index of schema documentation in { directory if directory != Path ('.' ) else 'root directory' } "
258+ generated: "{ datetime .now ().isoformat ()} "
259+ directory: "{ directory } "
260+ ---
261+
262+ # { dir_title }
263+
264+ """
265+
266+ # Add parent navigation
267+ if parent_link :
268+ content += f"{ parent_link } \n \n "
269+
270+ # Add schemas in this directory
271+ schemas_in_dir = schemas_by_dir .get (dir_key , [])
272+ if schemas_in_dir :
273+ content += "## Schemas in this directory\n \n "
274+ for schema_path in sorted (schemas_in_dir ):
275+ doc_path = schema_path .with_suffix ('.md' )
276+ schema_name = schema_path .stem .replace ('.schema' , '' )
277+
278+ # Calculate relative path from current index to schema
279+ if directory == Path ('.' ):
280+ rel_doc_path = str (doc_path )
281+ else :
282+ rel_doc_path = str (doc_path .relative_to (directory ))
283+
284+ content += f"- [{ schema_name } ]({ rel_doc_path } )\n "
285+ content += "\n "
286+
287+ # Add subdirectories
288+ subdirs = []
289+ for other_dir in all_directories :
290+ if other_dir != directory and other_dir != Path ('.' ):
291+ # Check if other_dir is a child of current directory
292+ try :
293+ if directory == Path ('.' ):
294+ # Root directory - check for immediate children
295+ if len (other_dir .parts ) == 1 :
296+ subdirs .append (other_dir )
297+ else :
298+ # Non-root directory - check if it's an immediate child
299+ if other_dir .parent == directory :
300+ subdirs .append (other_dir )
301+ except ValueError :
302+ # Not a relative path
303+ continue
304+
305+ if subdirs :
306+ content += "## Subdirectories\n \n "
307+ for subdir in sorted (subdirs ):
308+ if directory == Path ('.' ):
309+ subdir_link = f"{ subdir } /index.md"
310+ else :
311+ subdir_link = f"{ subdir .name } /index.md"
312+ content += f"- [{ subdir .name } /]({ subdir_link } )\n "
313+ content += "\n "
314+
315+ # Add generation info
316+ total_schemas_in_tree = len ([s for s in schemas_by_dir .values () for s in s ])
317+ content += f"""## Generation Info
318+
319+ - **Schemas in this directory**: { len (schemas_in_dir )}
320+ - **Total schemas in tree**: { total_schemas_in_tree }
321+ - **Generated**: { datetime .now ().strftime ('%Y-%m-%d %H:%M:%S' )}
322+ - **Source directory**: `{ src_path } `
323+ """
324+
325+ with open (index_file , 'w' ) as f :
326+ f .write (content )
327+
328+ print (f"Generated index: { index_file } " )
329+
330+
198331def generate_index (yaml_files , src_path , docs_path ):
199332 """Generate an index file listing all schemas."""
200333 index_file = docs_path / "index.md"
0 commit comments