mkdocs icon indicating copy to clipboard operation
mkdocs copied to clipboard

Prevent capitalisation of directory names in menu

Open mlevit opened this issue 5 years ago • 10 comments

I've noticed that when nav is not specified and mkdocs generates the navigation for me, it removes underscores (_) and capitalises the first letter. Is there a possibility to prevent this behaviour to happen:

image

This is what the directory structure looks like:

image

mlevit avatar Apr 30 '20 04:04 mlevit

The only way to control the formatting of section names in the nav is to define them in the config.

waylan avatar Apr 30 '20 17:04 waylan

@waylan that's not possible for me as the markdown files are auto-generated using a Python script, and hence I don't know how many pages I'm going to have.

I need mkdocs to pick up everything that is generated (which it's doing) but I just don't want mkdocs to change the naming conventions I use (i.e., lower case and non-caps).

Can a flag be added to mkdocs.yml to preserve my naming convention?

mlevit avatar Apr 30 '20 23:04 mlevit

No, this is not supported.

waylan avatar Apr 30 '20 23:04 waylan

@waylan do you think we could tweak

def dirname_to_title(dirname):
    """ Return a page tile obtained from a directory name. """
    title = dirname
    title = title.replace('-', ' ').replace('_', ' ')
    # Capitalize if the dirname was all lowercase, otherwise leave it as-is.
    if title.lower() == title:
        title = title.capitalize()

    return title

so it only modifies the paths when a variable in the config file is set to true?

mlevit avatar May 01 '20 01:05 mlevit

We try to keep the number of config settings to a minimum. In fact, any recent changes to the config settings have been to remove settings, not add them. I would suggest exploring using a plugin to accomplish what you want.

waylan avatar May 01 '20 13:05 waylan

The current behavior violates the Principle of Least Astonishment, as navigation menu options in the vast majority of English sites (at least) are in proper case instead of sentence case. One expects proper case to be the default behavior if it cannot be configured.

To turn it around, if there is a strong use case for sentence case, perhaps let those people then implement a plugin.

zgramana avatar May 15 '20 17:05 zgramana

I just ran into this issue. I would also prefer it to not capitalize and remove the underscores from the files/directories. I have a script that creates a markdown file from each source file and the capitalization and lack of underscores makes things look awkward

lstagner avatar Feb 01 '21 22:02 lstagner

Agree its weird that the title from the front matter doesn't let you override the default casing.

JackPott avatar Oct 27 '21 15:10 JackPott

I had the same problem, so I found a plugin that solves the problem. lukasgeiter/mkdocs-awesome-pages-plugin

After installing the plugin I added the .pages file inside the docs folder with content:

nav:
    - About: index.md
    - SSH: ssh
    - ...

The result:

image

amanbolat avatar Apr 16 '22 05:04 amanbolat

The awesome pages plugin does solve this problem but only if the pages have a top-level title:

# this-works
## this-does-not

analog-cbarber avatar Sep 20 '23 15:09 analog-cbarber