@@ -362,64 +362,102 @@ def _render_api_summary(
362362 return "\n " .join (lines ) + "\n "
363363
364364
365- def _render_root_summary (
365+ def _render_apiref_section_for_root_summary (
366366 handler_specs : dict [str , list [DocSpec ]],
367367 filter_specs : dict [str , list [DocSpec ]],
368- ) -> str :
369- """Render root literate-nav summary with fixed site order and dynamic APIref."""
368+ indent : int ,
369+ ) -> list [str ]:
370+ """Render dynamic APIref section for root SUMMARY.md at a given indent."""
371+ prefix = " " * indent
370372 lines = [
371- "- [Home](README.md)" ,
372- "- User Documentation" ,
373- " - [Tutorial](user/tutorial.md)" ,
374- " - [Concepts & explanation](user/explanation.md)" ,
375- " - How-to" ,
376- " - [Use handlers and filters](user/how-to/use-handlers.md)" ,
377- " - [Route messages](user/how-to/route-messages.md)" ,
378- " - [Add handlers at runtime](user/how-to/add-handlers-at-runtime.md)" ,
379- " - [Configure ERS](user/how-to/configure-ers.md)" ,
380- " - [Best practices](user/how-to/best-practices.md)" ,
381- " - [Troubleshooting](user/reference/troubleshooting.md)" ,
382- "- Developer Documentation" ,
383- " - [Concepts & explanation](dev/explanation.md)" ,
384- " - [Architecture reference](dev/reference/architecture.md)" ,
385- " - How-to" ,
386- " - [Add a handler](dev/how-to/add-a-handler.md)" ,
387- " - [Add a filter](dev/how-to/add-a-filter.md)" ,
388- " - [Debug routing](dev/how-to/debug-routing.md)" ,
389- " - [How docs work and how to update them](dev/how-to/update-documentation.md)" ,
390- " - [Common patterns](dev/reference/patterns.md)" ,
391- "- API reference" ,
392- " - [Overview](APIref/index.md)" ,
393- " - Logger APIs" ,
373+ f"{ prefix } - [Overview](APIref/index.md)" ,
374+ f"{ prefix } - Logger APIs" ,
394375 ]
395376
377+ child_prefix = " " * (indent + 1 )
396378 for title , _ in LOGGER_APIS :
397- lines .append (f" - [{ title } ](APIref/{ title } .md)" )
379+ lines .append (f"{ child_prefix } - [{ title } ](APIref/{ title } .md)" )
398380
399381 lines .extend (
400382 [
401- " - Registries" ,
402- " - Handlers" ,
403- " - [Overview](APIref/handlers/index.md)" ,
383+ f" { prefix } - Registries" ,
384+ f" { child_prefix } - Handlers" ,
385+ f" { ' ' * ( indent + 2 ) } - [Overview](APIref/handlers/index.md)" ,
404386 ]
405387 )
406388
407389 for type_name in sorted (handler_specs ):
408390 slug = _type_slug (type_name )
409- lines .append (f" - [{ type_name } ](APIref/handlers/{ slug } .md)" )
391+ lines .append (f"{ ' ' * ( indent + 2 ) } - [{ type_name } ](APIref/handlers/{ slug } .md)" )
410392
411393 lines .extend (
412394 [
413- " - Filters" ,
414- " - [Overview](APIref/filters/index.md)" ,
395+ f" { child_prefix } - Filters" ,
396+ f" { ' ' * ( indent + 2 ) } - [Overview](APIref/filters/index.md)" ,
415397 ]
416398 )
417399
418400 for type_name in sorted (filter_specs ):
419401 slug = _type_slug (type_name )
420- lines .append (f" - [{ type_name } ](APIref/filters/{ slug } .md)" )
402+ lines .append (f"{ ' ' * ( indent + 2 ) } - [{ type_name } ](APIref/filters/{ slug } .md)" )
421403
422- return "\n " .join (lines ) + "\n "
404+ return lines
405+
406+
407+ def _render_root_summary_from_mkdocs_nav (
408+ repo_root : Path ,
409+ handler_specs : dict [str , list [DocSpec ]],
410+ filter_specs : dict [str , list [DocSpec ]],
411+ ) -> str :
412+ """Render root SUMMARY.md from mkdocs.yml nav, with dynamic APIref expansion."""
413+ import yaml
414+
415+ mkdocs_config_path = repo_root / "mkdocs.yml"
416+ config = yaml .safe_load (mkdocs_config_path .read_text (encoding = "utf-8" )) or {}
417+ nav = config .get ("nav" )
418+
419+ if not isinstance (nav , list ):
420+ err_msg = "mkdocs.yml nav must be a list to generate root SUMMARY.md"
421+ raise ValueError (err_msg )
422+
423+ def render_nav_items (items : list [Any ], indent : int = 0 ) -> list [str ]:
424+ prefix = " " * indent
425+ lines : list [str ] = []
426+
427+ for item in items :
428+ if isinstance (item , str ):
429+ lines .append (f"{ prefix } - [{ item } ]({ item } )" )
430+ continue
431+
432+ if not isinstance (item , dict ) or len (item ) != 1 :
433+ err_msg = f"Unsupported nav item in mkdocs.yml: { item !r} "
434+ raise ValueError (err_msg )
435+
436+ title , value = next (iter (item .items ()))
437+
438+ if title == "API reference" and value == "APIref" :
439+ lines .append (f"{ prefix } - { title } " )
440+ lines .extend (
441+ _render_apiref_section_for_root_summary (
442+ handler_specs ,
443+ filter_specs ,
444+ indent + 1 ,
445+ )
446+ )
447+ continue
448+
449+ if isinstance (value , str ):
450+ lines .append (f"{ prefix } - [{ title } ]({ value } )" )
451+ elif isinstance (value , list ):
452+ lines .append (f"{ prefix } - { title } " )
453+ lines .extend (render_nav_items (value , indent + 1 ))
454+ else :
455+ err_msg = f"Unsupported nav value for '{ title } ': { value !r} "
456+ raise ValueError (err_msg )
457+
458+ return lines
459+
460+ return "\n " .join (render_nav_items (nav )) + "\n "
423461
424462
425463def _write_text (path : Path , content : str ) -> None :
@@ -471,7 +509,12 @@ def serialize(grouped: dict[str, list[DocSpec]]) -> dict[str, list[dict[str, Any
471509 }
472510
473511
474- def generate (output_root : Path , emit_json_manifest : bool , clean : bool ) -> list [Path ]:
512+ def generate (
513+ output_root : Path ,
514+ emit_json_manifest : bool ,
515+ clean : bool ,
516+ repo_root : Path | None = None ,
517+ ) -> list [Path ]:
475518 """Generate all targeted docs files and return paths written."""
476519 from daqpytools .logging .filters import FILTER_SPEC_REGISTRY
477520 from daqpytools .logging .handlers import HANDLER_SPEC_REGISTRY
@@ -542,10 +585,17 @@ def generate(output_root: Path, emit_json_manifest: bool, clean: bool) -> list[P
542585 written .append (summary_path )
543586
544587 if _USING_MKDOCS_GEN_FILES :
588+ if repo_root is None :
589+ err_msg = "repo_root is required when generating root SUMMARY.md"
590+ raise ValueError (err_msg )
545591 root_summary_path = Path ("SUMMARY.md" )
546592 _write_text (
547593 root_summary_path ,
548- _render_root_summary (handler_specs , filter_specs ),
594+ _render_root_summary_from_mkdocs_nav (
595+ repo_root ,
596+ handler_specs ,
597+ filter_specs ,
598+ ),
549599 )
550600 written .append (root_summary_path )
551601
@@ -610,6 +660,7 @@ def main() -> int:
610660 output_root = output_root ,
611661 emit_json_manifest = args .json_manifest ,
612662 clean = args .clean ,
663+ repo_root = repo_root ,
613664 )
614665
615666 print (f"Generated { len (written )} files under: { output_root } " ) # noqa: T201
@@ -634,6 +685,7 @@ def _run_from_mkdocs_gen_files() -> None:
634685 output_root = output_root ,
635686 emit_json_manifest = False ,
636687 clean = False ,
688+ repo_root = repo_root ,
637689 )
638690
639691
0 commit comments