Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "clean_names" option #2715

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion mkdocs/config/defaults.py
Expand Up @@ -121,5 +121,8 @@ def get_schema():
('plugins', config_options.Plugins(default=['search'])),

# a list of extra paths to watch while running `mkdocs serve`
('watch', config_options.ListOfPaths(default=[]))
('watch', config_options.ListOfPaths(default=[])),

# Clean the directory names when auto generating page names from them
('clean_names', config_options.Type(bool, default=True))
)
2 changes: 1 addition & 1 deletion mkdocs/structure/nav.py
Expand Up @@ -97,7 +97,7 @@ def _indent_print(self, depth=0):

def get_navigation(files, config):
""" Build site navigation from config and files."""
nav_config = config['nav'] or nest_paths(f.src_path for f in files.documentation_pages())
nav_config = config['nav'] or nest_paths([f.src_path for f in files.documentation_pages()], config)
items = _data_to_navigation(nav_config, files, config)
if not isinstance(items, list):
items = [items]
Expand Down
13 changes: 9 additions & 4 deletions mkdocs/structure/pages.py
Expand Up @@ -36,6 +36,8 @@ def __init__(self, title, file, config):
self._set_canonical_url(config.get('site_url', None))
self._set_edit_url(config.get('repo_url', None), config.get('edit_uri', None))

self.clean_names = config.get('clean_names', None)

# Placeholders to be filled in later in the build process.
self.markdown = None
self.content = None
Expand Down Expand Up @@ -152,10 +154,13 @@ def _set_title(self):
if self.is_homepage:
title = 'Home'
else:
title = self.file.name.replace('-', ' ').replace('_', ' ')
# Capitalize if the filename was all lowercase, otherwise leave it as-is.
if title.lower() == title:
title = title.capitalize()
if self.clean_names:
title = self.file.name.replace('-', ' ').replace('_', ' ')
# Capitalize if the filename was all lowercase, otherwise leave it as-is.
if title.lower() == title:
title = title.capitalize()
else:
title = self.file.name

self.title = title

Expand Down
7 changes: 5 additions & 2 deletions mkdocs/utils/__init__.py
Expand Up @@ -398,7 +398,7 @@ def find_or_create_node(branch, key):
return new_branch


def nest_paths(paths):
def nest_paths(paths, config):
"""
Given a list of paths, convert them into a nested structure that will match
the pages config.
Expand All @@ -415,8 +415,11 @@ def nest_paths(paths):
parts = directory.split(os.path.sep)

branch = nested

clean_names = config.get('clean_names', None)
for part in parts:
part = dirname_to_title(part)
if clean_names:
part = dirname_to_title(part)
branch = find_or_create_node(branch, part)

branch.append(path)
Expand Down