Populate MkPages from SUMMARY.mdΒΆ

MkNavs can parse index files in SUMMARY.md style (as popularized by mkdocs-literate-nav).

Given the following folder structure:

Directory tree

πŸ“‚ `nav_tree`
┣━━ πŸ“‚ `test_folder`
┃   ┣━━ πŸ“ `markdown-exec.md (507 Bytes)`
┃   ┗━━ πŸ“ `sub_1.md (286 Bytes)`
┣━━ πŸ“‚ `test_subnav`
┃   ┣━━ πŸ“ `subnav_page_1.md (132 Bytes)`
┃   ┣━━ πŸ“ `subnav_page_2.md (1.7 kB)`
┃   ┗━━ πŸ“ `SUMMARY.md (72 Bytes)`
┣━━ πŸ“ `SUMMARY.md (162 Bytes)`
┗━━ πŸ“ `test_file.md (55 Bytes)`

and a root SUMMARY.md looking like:

Root SUMMARY.md

* Test nested
    * [General] (test_folder/sub_1.md)
    * [Markdown-Exec] (test_folder/markdown-exec.md)
* [Test Subnav] (test_subnav/)
* [Test file] (test_file.md)

Page info
Code for this section
mknodes.manual.navs_section._ΒΆ
20@nav.route.nav("Populate MkPages from SUMMARY.md")
21def _(nav: mk.MkNav) -> None:
22    folder = paths.TEST_RESOURCES / "nav_tree/"
23    summary_file = folder / "SUMMARY.md"
24    nav.parse.file(summary_file, hide="toc")
25    page = nav.add_page(is_index=True, hide="toc", icon="file")
26    text = summary_file.read_text("utf-8")
27    text = text.replace("](", "] (")
28    path = paths.TEST_RESOURCES / "nav_tree/"
29    variables = dict(path=path, text=text)
30    page += mk.MkTemplate("navs/nav_from_file.jinja", variables=variables)
Resources
Resources(css=[],
          markdown_extensions={'admonition': {},
                               'pymdownx.details': {},
                               'pymdownx.superfences': {}},
          plugins=[],
          js=[],
          assets=[],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/navs_section.py
  source_function: _
  source_line_no: 20
hide:
- toc
icon: material/file
title: Populate MkPages from SUMMARY.md