question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support a plugin to allow clickable sections that lead to an index page

See original GitHub issue

I have developed a plugin for MkDocs, “section-index” that allows sections in the left-side nav to be not just expandable, but also have a link to a page directly associated with them.

The plugin already fully works as-is (you can use it!), but the implementation currently needs to “hack into” the templates of themes (such as mkdocs-material and others). So I am reaching out to ensure good long-term support of this idea.

mkdocs-material theme could integrate optional “code paths” directly into its templates in a way that has 0 effect when the plugin isn’t loaded, and if it is loaded, the template directly works with the “protocol” provided by it, without hacks.

Demos

A real website using this

Screencast with comparison

Screencast with comparison

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

plugins:
  - section-index

The above demo features this^ mkdocs.yml config. Obviously by default in MkDocs this means something else, but with this plugin, the borgs/index.md page is merged as the index of the “Borgs” section.

Details

Other than the part that rewrites theme templates, the core of this plugin is the code that modifies the nav object. When it encounters a Section and a Page in a configuration like above, it collapses the two into one object, which is a hybrid of properties of both:

  • title: str
  • url: str (normally exclusive to Page)
  • children: list (normally exclusive to Section)
  • is_page = True
  • is_section = True

The condition for this collapsing is up for discussion, but currently it’s very “permissive”. Just any page that’s specified only as a link (no title), if it’s the first item of a section, becomes merged as the index page of the section. The idea is for people to always specify names for all pages in the nav except for the section-title ones.

Other approaches are possible, but it’s certainly not as easy as just checking against index.md.

With this, all that a theme needs to do is consider the case where both url and children are present (without this plugin that can never happen), and render a “section-page” as part of the navigation menu.

An individual theme could actually implement this feature on its own (no plugin), by checking for such conditions directly within Jinja templates, but I personally find that less clean. See my further arguments on this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:32 (30 by maintainers)

github_iconTop GitHub Comments

1reaction
squidfunkcommented, Feb 1, 2021

@jaceklaskowski it was the wrong link in the issue here, yeah, haven’t seen the localhost part when I copied it. This is now fixed in my comment.

1reaction
squidfunkcommented, Jan 31, 2021

Awesome, any feedback appreciated 😎

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plugin for MkDocs to allow clickable sections that lead to an index ...
Description : Plugin for MkDocs to allow clickable sections that lead to an index page. Normally sections in MkDocs cannot be clickable as...
Read more >
Section Index Generator | Figma Community
Section Index Generator ... Add a clickable section index in your first page to make your file structure clearer. ✓ Automatically scan through...
Read more >
How to Create a Table of Contents in WordPress Manually or ...
Table of Contents Plus is a WordPress plugin that allows you to create an index or table of contents on long-form pages and...
Read more >
Bug#1014399: marked as done (ITP: mkdocs-section-index -- Plugin ...
... Plugin for MkDocs to allow clickable sections that lead to an index page) ... (implemented within the plugin), or support from themes...
Read more >
WordPress Anchor Links and Jump Links
In the classic editor, you need the target text and the link to create a page jump. Clicking on the link will take...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found