You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Agreed. I'd like the casing to be preserved by default. But since there is already a standing precedent of upcasing, I'd be happy with an option to preserve.
Actually, this seems a bit more convoluted. It appears as if single entities are converted to initialcase, as is anything with a dot-naming convention, whereas camelcase is not.
The URI, however, seems to maintain the original casing.
Weird, it isn't consistent either: namespace.fn.method.md gets initial-cased, but another file with the same naming convention namespace.fn.otherMethod.md does not.
Or perhaps it is consistent. The difference seems to be that one is entirely lc, while the other is camelCase.
This is not a configurable option, but is hard-coded. And we are very resistant to adding new configuration options. In fact, we've removed more than we've added in the last few releases.
The behavior is rather simple. If a filename is all lower case, then Python's string.capitalize method is run on it (capitalize first character of string). If the filename is not all lowercase, then no capitalization is done. The current behavior was put in place over 4 years ago (see ed59436), with a slightly simpler variation (which didn't check existing case) being added one day earlier (see c38db61). Prior to that titles were not derived from filenames and there have been no other changes to title generation since (except for the code being moved without any changes in behavior in 984029a). I find it curious that this is the first we have had any complaints about it.
In any event, we are intending to rework the way titles are determined in the next major release (see #316). And if that doesn't meet your needs, the new Plugin API (see #1223) might be a way for users to define their own method for defining page titles. The work on these things can be found in the 1.0.dev branch.
Don’t get me wrong, not trying to dog you guys for it, just found it curious as it seemed somewhat unexpected especially when I couldn’t find any info on it. I expected to find at least one random topic on it somewhere.
Though I agree it’s also strange if no one ever mentioned this before, we’re not doing anything crazy with our naming conventions (standard JS namespace dot notation), so I’d be shocked if I’m the first person who ran into it. Of course, running into it and then digging into it are two separate things, or perhaps people found other workarounds or just decided it wasn’t that crucial for their needs.
It’s not a dealbreaker for me (kinda sorta), liking what I can do so far with the tool otherwise, and I’m going to need to customize some things anyway so perhaps I’ll work around it.
This is one of the feature/change request where everybody wants something different, and it is almost impossible to satisfy everyone with the default behavior. The current default behavior is good in probably 90% of cases (maybe more, maybe less).
The most obvious solution to this is to declare titles in YAML front-matter metadata in each file:
---title: my title---
blabla
But there are alternatives.
Instead of adding a configuration option with multiple predefined values and the according behaviors, we could add it but make it accept a Python function (using YAML Python tags) that accepts input objects from MkDocs and returns a title for the navigation. This way users could implement their own behavior.
A current, possible solution would be to hook into on_nav to iterate on the navigation items and update them as you see fit. A very basic example:
# hooks.pyfrompathlibimportPathdefon_nav(env, config, files):
forfileinfiles:
iffile.page:
# Restore origin file name (without extension) as title.file.page.title=Path(file.src_uri).stem
# mkdocs.ymlhooks:
- hooks.py
Since it seems to be achievable through hooks and plugins, I'll close this as out of scope for MkDocs core. If the plugin API can be improved though, please let us know!
Activity
trel commentedon Sep 20, 2017
Agreed. I'd like the casing to be preserved by default. But since there is already a standing precedent of upcasing, I'd be happy with an option to preserve.
joshrhoades commentedon Sep 20, 2017
Actually, this seems a bit more convoluted. It appears as if single entities are converted to initialcase, as is anything with a dot-naming convention, whereas camelcase is not.
The URI, however, seems to maintain the original casing.
namespace.fn.method.mdNamespace.fn.methodnamespace.fn.methodhide.mdHidehidegetActualSize.mdgetActualSizegetActualSizetest thisTest thistest%20thistrel commentedon Sep 20, 2017
Yes, our current workaround is to specify anything that isn't vanilla initial upcase.
Every other scenario behaved surprisingly.
joshrhoades commentedon Sep 20, 2017
kebab-case and snake_case also get the Initial case treatment too:
test-thisTest thistest-thistest_thisTest thistest_thisA configurable option to preserve casing as entered would be ideal to my mind, without impacting already existing usages/behaviors.
joshrhoades commentedon Sep 20, 2017
Weird, it isn't consistent either:
namespace.fn.method.mdgets initial-cased, but another file with the same naming conventionnamespace.fn.otherMethod.mddoes not.Or perhaps it is consistent. The difference seems to be that one is entirely lc, while the other is camelCase.
waylan commentedon Sep 21, 2017
This is not a configurable option, but is hard-coded. And we are very resistant to adding new configuration options. In fact, we've removed more than we've added in the last few releases.
The behavior is rather simple. If a filename is all lower case, then Python's string.capitalize method is run on it (capitalize first character of string). If the filename is not all lowercase, then no capitalization is done. The current behavior was put in place over 4 years ago (see ed59436), with a slightly simpler variation (which didn't check existing case) being added one day earlier (see c38db61). Prior to that titles were not derived from filenames and there have been no other changes to title generation since (except for the code being moved without any changes in behavior in 984029a). I find it curious that this is the first we have had any complaints about it.
In any event, we are intending to rework the way titles are determined in the next major release (see #316). And if that doesn't meet your needs, the new Plugin API (see #1223) might be a way for users to define their own method for defining page titles. The work on these things can be found in the 1.0.dev branch.
joshrhoades commentedon Sep 21, 2017
@waylan Thanks for the info.
Don’t get me wrong, not trying to dog you guys for it, just found it curious as it seemed somewhat unexpected especially when I couldn’t find any info on it. I expected to find at least one random topic on it somewhere.
Though I agree it’s also strange if no one ever mentioned this before, we’re not doing anything crazy with our naming conventions (standard JS namespace dot notation), so I’d be shocked if I’m the first person who ran into it. Of course, running into it and then digging into it are two separate things, or perhaps people found other workarounds or just decided it wasn’t that crucial for their needs.
It’s not a dealbreaker for me (kinda sorta), liking what I can do so far with the tool otherwise, and I’m going to need to customize some things anyway so perhaps I’ll work around it.
Thanks for the info, guys.
0xTirthesh commentedon Aug 27, 2020
I know this thread is too old - but I had to ask, are you guys planning any update on this?
waylan commentedon Aug 27, 2020
@ganatrat the last activity was to give this the [needs design decision] tag. Until a decision is made, there are no plans.
pawamoy commentedon Apr 15, 2024
This is one of the feature/change request where everybody wants something different, and it is almost impossible to satisfy everyone with the default behavior. The current default behavior is good in probably 90% of cases (maybe more, maybe less).
The most obvious solution to this is to declare titles in YAML front-matter metadata in each file:
But there are alternatives.
Instead of adding a configuration option with multiple predefined values and the according behaviors, we could add it but make it accept a Python function (using YAML Python tags) that accepts input objects from MkDocs and returns a title for the navigation. This way users could implement their own behavior.
A current, possible solution would be to hook into
on_navto iterate on the navigation items and update them as you see fit. A very basic example:Since it seems to be achievable through hooks and plugins, I'll close this as out of scope for MkDocs core. If the plugin API can be improved though, please let us know!