Skip to content

Prevent capitalisation of directory names in menu #2086

Closed as not planned
Closed as not planned

Description

@mlevit

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

Activity

  1. waylan commented on Apr 30, 2020

    @waylan
    Contributor

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

  2. mlevit commented on Apr 30, 2020

    @mlevit
    Author

    @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?

  3. waylan commented on Apr 30, 2020

    @waylan
    Contributor

    No, this is not supported.

  4. mlevit commented on May 1, 2020

    @mlevit
    Author

    @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?

  5. waylan commented on May 1, 2020

    @waylan
    Contributor

    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.

  6. zgramana commented on May 15, 2020

    @zgramana

    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.

  7. lstagner commented on Feb 1, 2021

    @lstagner

    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

  8. JackPott commented on Oct 27, 2021

    @JackPott

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

  9. amanbolat commented on Apr 16, 2022

    @amanbolat

    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

  10. analog-cbarber commented on Sep 20, 2023

    @analog-cbarber

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

    # this-works
    ## this-does-not
  11. pawamoy commented on Apr 17, 2024

    @pawamoy
    Contributor

    Similar to #1289, see comment #1289 (comment). Additionally, it's partially solved by the awesome pages plugin. For the reasons mentioned here and in the linked comment, we'll close as out of scope for now. Feel free to comment further or ask to re--open if you'd like to work on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions