How to add permalinks to tree nodes in Markdown nav file (mkdocs.yml)?

后端 未结 2 962
情话喂你
情话喂你 2021-01-13 21:36

The mkdocs.yml nav file I am working with includes a hierarchical tree of a manuals website with several categories and subcategories the content articles fall into; the tre

2条回答
  •  被撕碎了的回忆
    2021-01-13 22:10

    I have implemented a plugin for this functionality, "mkdocs-section-index", and it works similarly to what @Waylan describes -- or actually more similar to the dropped pull request #1042, because most of the logic is outside of the theme/template. The special sections with a link are explicitly put into the nav and presented as such to the theme, so it doesn't need to find and exclude this "first child" itself.

    mkdocs.yml:

    plugins:
      - section-index
    nav:
      - Frob: index.md
      - Baz: baz.md
      - Borgs:
        - borgs/index.md
        - Bar: borgs/bar.md
        - Foo: borgs/foo.md
    

    That gives you a nav like this:

    • Frob
    • Baz
    • Borgs
      • Bar
      • Foo

    It makes sense to me that this functionality couldn't be included by default, but a plugin as a way to opt in seems perfectly fine.

提交回复
热议问题