Repository: mkdocs/mkdocs

Issue:
Regression when building docs
I got this when building the Django REST Framework docs with 0.12.1

```
$ mkdocs build 
Building documentation to directory: site
Directory site contains stale files. Use --clean to remove them.
Traceback (most recent call last):
  File "/home/dougalmatthews/.virtualenvs/mkdocs/bin/mkdocs", line 9, in <module>
    load_entry_point('mkdocs==0.12.1', 'console_scripts', 'mkdocs')()
  File "/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/main.py", line 77, in run_main
    main(cmd, args=sys.argv[2:], options=dict(opts))
  File "/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/main.py", line 52, in main
    build(config, clean_site_dir=clean_site_dir)
  File "/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/build.py", line 252, in build
    build_pages(config)
  File "/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/build.py", line 209, in build_pages
    site_navigation = nav.SiteNavigation(config['pages'], config['use_directory_urls'])
  File "/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/nav.py", line 37, in __init__
    _generate_site_navigation(pages_config, self.url_context, use_directory_urls)
  File "/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/nav.py", line 243, in _generate_site_navigation
    header.children.append(page)
AttributeError: 'Page' object has no attribute 'children'
```



Discussion:
The issue is when you don't specify the title for some pages but do for others. For example:

```
 - ['topics/ajax-csrf-cors.md', 'Topics', 'AJAX, CSRF & CORS']
 - ['topics/browser-enhancements.md', 'Topics', ]
 - ['topics/browsable-api.md', 'Topics', 'The Browsable API']
```

The build fails on `topics/browser-enhancements.md`


Resolving patch:
diff --git a/mkdocs/nav.py b/mkdocs/nav.py
--- a/mkdocs/nav.py
+++ b/mkdocs/nav.py
@@ -224,6 +224,13 @@ def _generate_site_navigation(pages_config, url_context, use_directory_urls=True
             filename = path.split(os.path.sep)[0]
             title = filename_to_title(filename)
 
+        # If we don't have a child title but the other title is the same, we
+        # should be within a section and the child title needs to be inferred
+        # from the filename.
+        if len(nav_items) and title == nav_items[-1].title == title and child_title is None:
+            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:


Test patch:
diff --git a/mkdocs/tests/nav_tests.py b/mkdocs/tests/nav_tests.py
--- a/mkdocs/tests/nav_tests.py
+++ b/mkdocs/tests/nav_tests.py
@@ -63,6 +63,30 @@ def test_indented_toc(self):
         self.assertEqual(len(site_navigation.nav_items), 3)
         self.assertEqual(len(site_navigation.pages), 6)
 
+    def test_indented_toc_missing_child_title(self):
+        pages = [
+            ('index.md', 'Home'),
+            ('api-guide/running.md', 'API Guide', 'Running'),
+            ('api-guide/testing.md', 'API Guide'),
+            ('api-guide/debugging.md', 'API Guide', 'Debugging'),
+            ('about/release-notes.md', 'About', 'Release notes'),
+            ('about/license.md', 'About', 'License')
+        ]
+        expected = dedent("""
+        Home - /
+        API Guide
+            Running - /api-guide/running/
+            Testing - /api-guide/testing/
+            Debugging - /api-guide/debugging/
+        About
+            Release notes - /about/release-notes/
+            License - /about/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), 6)
+
     def test_nested_ungrouped(self):
         pages = [
             ('index.md', 'Home'),