mkdocs icon indicating copy to clipboard operation
mkdocs copied to clipboard

smart section titles when no navigation is configured

Open realtimeprojects opened this issue 1 year ago • 6 comments

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

realtimeprojects avatar Aug 27 '23 14:08 realtimeprojects

+1 to this feature, the default section titles are not ideal, it's also hard to sort the directory order.

zinizhu avatar Sep 06 '23 05:09 zinizhu

Perhaps you could provide a short example?

tomchristie avatar Apr 15 '24 12:04 tomchristie

This repository contains a simple example:

https://github.com/realtimeprojects/mkdocs-sample/tree/master

This is how the page looks like at the moment:

Screen Shot 2024-04-20 at 15 18 23

Given the feature smart_section_titles is enabled, the page should look like this:

Screen Shot 2024-04-20 at 15 17 31

realtimeprojects avatar Apr 20 '24 13:04 realtimeprojects

Here is the PR with a basic implementation: https://github.com/mkdocs/mkdocs/pull/3656

realtimeprojects avatar Apr 20 '24 13:04 realtimeprojects

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.

oprypin avatar Apr 20 '24 14:04 oprypin

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.

oprypin avatar Apr 20 '24 14:04 oprypin