Skip to content

Commit

Permalink
Merge 73bd963 into 88bb485
Browse files Browse the repository at this point in the history
  • Loading branch information
d0ugal committed Apr 2, 2015
2 parents 88bb485 + 73bd963 commit 0421ba1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
11 changes: 7 additions & 4 deletions mkdocs/nav.py
Expand Up @@ -209,14 +209,17 @@ def _generate_site_navigation(pages_config, url_context, use_directory_urls=True
)
raise exceptions.ConfigurationError(msg)

# If both the title and child_title are None, then we
# have just been given a path. If that path contains a /
# then lets automatically nest it.
if title is None and child_title is None and os.path.sep in path:
filename = path.split(os.path.sep)[-1]
child_title = filename_to_title(filename)

if title is None:
filename = path.split(os.path.sep)[0]
title = filename_to_title(filename)

if child_title is None and os.path.sep in path:
filename = path.split(os.path.sep)[-1]
child_title = filename_to_title(filename)

url = utils.get_url_path(path, use_directory_urls)

if not child_title:
Expand Down
33 changes: 33 additions & 0 deletions mkdocs/tests/nav_tests.py
Expand Up @@ -63,6 +63,39 @@ def test_indented_toc(self):
self.assertEqual(len(site_navigation.nav_items), 3)
self.assertEqual(len(site_navigation.pages), 6)

def test_nested_ungrouped(self):
pages = [
('index.md', 'Home'),
('about/contact.md', 'Contact'),
('about/sub/license.md', 'License Title')
]
expected = dedent("""
Home - /
Contact - /about/contact/
License Title - /about/sub/license/
""")
site_navigation = nav.SiteNavigation(pages)
self.assertEqual(str(site_navigation).strip(), expected)
self.assertEqual(len(site_navigation.nav_items), 3)
self.assertEqual(len(site_navigation.pages), 3)

def test_nested_ungrouped_no_titles(self):
pages = [
('index.md',),
('about/contact.md'),
('about/sub/license.md')
]
expected = dedent("""
Home - /
About
Contact - /about/contact/
License - /about/sub/license/
""")
site_navigation = nav.SiteNavigation(pages)
self.assertEqual(str(site_navigation).strip(), expected)
self.assertEqual(len(site_navigation.nav_items), 2)
self.assertEqual(len(site_navigation.pages), 3)

def test_walk_simple_toc(self):
pages = [
('index.md', 'Home'),
Expand Down

0 comments on commit 0421ba1

Please sign in to comment.