mkdocs
mkdocs copied to clipboard
smart section titles when no navigation is configured
Given no navigation tree is defined in the configuration, the section titles for sub-directories should be determined by the following logic:
- if an index page is defined, use the title of the index page, hereby the title from the meta data of the index page should be prefered to the title from the markdown in order to allow using a different title than the actual page title for the navigation menu.
- If no index page is defined, keep the logic "as-is".
The user should be able to turn on/off this behaviour by a configuration option, e.g.
theme:
features:
- navigation.smart-section-titles
+1 to this feature, the default section titles are not ideal, it's also hard to sort the directory order.
Perhaps you could provide a short example?
This repository contains a simple example:
https://github.com/realtimeprojects/mkdocs-sample/tree/master
This is how the page looks like at the moment:
Given the feature smart_section_titles
is enabled, the page should look like this:
Here is the PR with a basic implementation: https://github.com/mkdocs/mkdocs/pull/3656
Thanks for the example site, that does make it clear.
The functionality that this request is about is specific to mkdocs-material. It doesn't make sense to apply a workaround in MkDocs to make section titles calculated based on a page, because in MkDocs there's never any direct relation between a section and a page inside it. If you try this with any other theme, it doesn't make any sense anymore.
I tried this out with the plugin "mkdocs-section-index", which does create these explicit associations in a generic way, but sadly it suffers from the same deficiency. Though implementing this functionality there would make a lot of sense.
And let me leave you with a fun tidbit.
This example site contains all kinds of plugins and extensions that one would need to install. But I don't need to do any of that to try it out.
I just create the following file hatch.toml
inside the directory:
[env]
requires = ["hatch-mkdocs"]
[env.collectors.mkdocs.docs]
And then running hatch run docs:serve
does all the steps to view the site.