We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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'
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mkdocs/nav.py`
Content:
```
1 # coding: utf-8
2 
3 """
4 Deals with generating the site-wide navigation.
5 
6 This consists of building a set of interlinked page and header objects.
7 """
8 
9 import logging
10 import os
11 
12 from mkdocs import utils, exceptions
13 
14 log = logging.getLogger(__name__)
15 
16 
17 def filename_to_title(filename):
18     """
19     Automatically generate a default title, given a filename.
20     """
21     if utils.is_homepage(filename):
22         return 'Home'
23 
24     title = os.path.splitext(filename)[0]
25     title = title.replace('-', ' ').replace('_', ' ')
26     # Captialize if the filename was all lowercase, otherwise leave it as-is.
27     if title.lower() == title:
28         title = title.capitalize()
29     return title
30 
31 
32 class SiteNavigation(object):
33     def __init__(self, pages_config, use_directory_urls=True):
34         self.url_context = URLContext()
35         self.file_context = FileContext()
36         self.nav_items, self.pages = \
37             _generate_site_navigation(pages_config, self.url_context, use_directory_urls)
38         self.homepage = self.pages[0] if self.pages else None
39         self.use_directory_urls = use_directory_urls
40 
41     def __str__(self):
42         return ''.join([str(item) for item in self])
43 
44     def __iter__(self):
45         return iter(self.nav_items)
46 
47     def walk_pages(self):
48         """
49         Returns each page in the site in turn.
50 
51         Additionally this sets the active status of the pages and headers,
52         in the site navigation, so that the rendered navbar can correctly
53         highlight the currently active page and/or header item.
54         """
55         page = self.homepage
56         page.set_active()
57         self.url_context.set_current_url(page.abs_url)
58         self.file_context.set_current_path(page.input_path)
59         yield page
60         while page.next_page:
61             page.set_active(False)
62             page = page.next_page
63             page.set_active()
64             self.url_context.set_current_url(page.abs_url)
65             self.file_context.set_current_path(page.input_path)
66             yield page
67         page.set_active(False)
68 
69     @property
70     def source_files(self):
71         if not hasattr(self, '_source_files'):
72             self._source_files = set([page.input_path for page in self.pages])
73         return self._source_files
74 
75 
76 class URLContext(object):
77     """
78     The URLContext is used to ensure that we can generate the appropriate
79     relative URLs to other pages from any given page in the site.
80 
81     We use relative URLs so that static sites can be deployed to any location
82     without having to specify what the path component on the host will be
83     if the documentation is not hosted at the root path.
84     """
85 
86     def __init__(self):
87         self.base_path = '/'
88 
89     def set_current_url(self, current_url):
90         self.base_path = os.path.dirname(current_url)
91 
92     def make_relative(self, url):
93         """
94         Given a URL path return it as a relative URL,
95         given the context of the current page.
96         """
97         suffix = '/' if (url.endswith('/') and len(url) > 1) else ''
98         # Workaround for bug on `os.path.relpath()` in Python 2.6
99         if self.base_path == '/':
100             if url == '/':
101                 # Workaround for static assets
102                 return '.'
103             return url.lstrip('/')
104         # Under Python 2.6, relative_path adds an extra '/' at the end.
105         relative_path = os.path.relpath(url, start=self.base_path).rstrip('/') + suffix
106 
107         return utils.path_to_url(relative_path)
108 
109 
110 class FileContext(object):
111     """
112     The FileContext is used to ensure that we can generate the appropriate
113     full path for other pages given their relative path from a particular page.
114 
115     This is used when we have relative hyperlinks in the documentation, so that
116     we can ensure that they point to markdown documents that actually exist
117     in the `pages` config.
118     """
119     def __init__(self):
120         self.current_file = None
121         self.base_path = ''
122 
123     def set_current_path(self, current_path):
124         self.current_file = current_path
125         self.base_path = os.path.dirname(current_path)
126 
127     def make_absolute(self, path):
128         """
129         Given a relative file path return it as a POSIX-style
130         absolute filepath, given the context of the current page.
131         """
132         return os.path.normpath(os.path.join(self.base_path, path))
133 
134 
135 class Page(object):
136     def __init__(self, title, url, path, url_context):
137         self.title = title
138         self.abs_url = url
139         self.active = False
140         self.url_context = url_context
141 
142         # Relative paths to the input markdown file and output html file.
143         self.input_path = path
144         self.output_path = utils.get_html_path(path)
145 
146         # Links to related pages
147         self.previous_page = None
148         self.next_page = None
149         self.ancestors = []
150 
151     @property
152     def url(self):
153         return self.url_context.make_relative(self.abs_url)
154 
155     @property
156     def is_homepage(self):
157         return utils.is_homepage(self.input_path)
158 
159     def __str__(self):
160         return self._indent_print()
161 
162     def _indent_print(self, depth=0):
163         indent = '    ' * depth
164         active_marker = ' [*]' if self.active else ''
165         title = self.title if (self.title is not None) else '[blank]'
166         return '%s%s - %s%s\n' % (indent, title, self.abs_url, active_marker)
167 
168     def set_active(self, active=True):
169         self.active = active
170         for ancestor in self.ancestors:
171             ancestor.active = active
172 
173 
174 class Header(object):
175     def __init__(self, title, children):
176         self.title, self.children = title, children
177         self.active = False
178 
179     def __str__(self):
180         return self._indent_print()
181 
182     def _indent_print(self, depth=0):
183         indent = '    ' * depth
184         active_marker = ' [*]' if self.active else ''
185         ret = '%s%s%s\n' % (indent, self.title, active_marker)
186         for item in self.children:
187             ret += item._indent_print(depth + 1)
188         return ret
189 
190 
191 def _generate_site_navigation(pages_config, url_context, use_directory_urls=True):
192     """
193     Returns a list of Page and Header instances that represent the
194     top level site navigation.
195     """
196     nav_items = []
197     pages = []
198     previous = None
199 
200     for config_line in pages_config:
201         if isinstance(config_line, str):
202             path = os.path.normpath(config_line)
203             title, child_title = None, None
204         elif len(config_line) in (1, 2, 3):
205             # Pad any items that don't exist with 'None'
206             padded_config = (list(config_line) + [None, None])[:3]
207             path, title, child_title = padded_config
208             path = os.path.normpath(path)
209         else:
210             msg = (
211                 "Line in 'page' config contained %d items.  "
212                 "Expected 1, 2 or 3 strings." % len(config_line)
213             )
214             raise exceptions.ConfigurationError(msg)
215 
216         # If both the title and child_title are None, then we
217         # have just been given a path. If that path contains a /
218         # then lets automatically nest it.
219         if title is None and child_title is None and os.path.sep in path:
220             filename = path.split(os.path.sep)[-1]
221             child_title = filename_to_title(filename)
222 
223         if title is None:
224             filename = path.split(os.path.sep)[0]
225             title = filename_to_title(filename)
226 
227         url = utils.get_url_path(path, use_directory_urls)
228 
229         if not child_title:
230             # New top level page.
231             page = Page(title=title, url=url, path=path, url_context=url_context)
232             nav_items.append(page)
233         elif not nav_items or (nav_items[-1].title != title):
234             # New second level page.
235             page = Page(title=child_title, url=url, path=path, url_context=url_context)
236             header = Header(title=title, children=[page])
237             nav_items.append(header)
238             page.ancestors = [header]
239         else:
240             # Additional second level page.
241             page = Page(title=child_title, url=url, path=path, url_context=url_context)
242             header = nav_items[-1]
243             header.children.append(page)
244             page.ancestors = [header]
245 
246         # Add in previous and next information.
247         if previous:
248             page.previous_page = previous
249             previous.next_page = page
250         previous = page
251 
252         pages.append(page)
253 
254     return (nav_items, pages)
255
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mkdocs/nav.py b/mkdocs/nav.py
--- a/mkdocs/nav.py
+++ b/mkdocs/nav.py
@@ -224,6 +224,13 @@
             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:

{"golden_diff": "diff --git a/mkdocs/nav.py b/mkdocs/nav.py\n--- a/mkdocs/nav.py\n+++ b/mkdocs/nav.py\n@@ -224,6 +224,13 @@\n             filename = path.split(os.path.sep)[0]\n             title = filename_to_title(filename)\n \n+        # If we don't have a child title but the other title is the same, we\n+        # should be within a section and the child title needs to be inferred\n+        # from the filename.\n+        if len(nav_items) and title == nav_items[-1].title == title and child_title is None:\n+            filename = path.split(os.path.sep)[-1]\n+            child_title = filename_to_title(filename)\n+\n         url = utils.get_url_path(path, use_directory_urls)\n \n         if not child_title:\n", "issue": "Regression when building docs\nI got this when building the Django REST Framework docs with 0.12.1\n\n```\n$ mkdocs build \nBuilding documentation to directory: site\nDirectory site contains stale files. Use --clean to remove them.\nTraceback (most recent call last):\n  File \"/home/dougalmatthews/.virtualenvs/mkdocs/bin/mkdocs\", line 9, in <module>\n    load_entry_point('mkdocs==0.12.1', 'console_scripts', 'mkdocs')()\n  File \"/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/main.py\", line 77, in run_main\n    main(cmd, args=sys.argv[2:], options=dict(opts))\n  File \"/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/main.py\", line 52, in main\n    build(config, clean_site_dir=clean_site_dir)\n  File \"/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/build.py\", line 252, in build\n    build_pages(config)\n  File \"/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/build.py\", line 209, in build_pages\n    site_navigation = nav.SiteNavigation(config['pages'], config['use_directory_urls'])\n  File \"/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/nav.py\", line 37, in __init__\n    _generate_site_navigation(pages_config, self.url_context, use_directory_urls)\n  File \"/home/dougalmatthews/.virtualenvs/mkdocs/lib/python2.7/site-packages/mkdocs/nav.py\", line 243, in _generate_site_navigation\n    header.children.append(page)\nAttributeError: 'Page' object has no attribute 'children'\n```\n\n", "before_files": [{"content": "# coding: utf-8\n\n\"\"\"\nDeals with generating the site-wide navigation.\n\nThis consists of building a set of interlinked page and header objects.\n\"\"\"\n\nimport logging\nimport os\n\nfrom mkdocs import utils, exceptions\n\nlog = logging.getLogger(__name__)\n\n\ndef filename_to_title(filename):\n    \"\"\"\n    Automatically generate a default title, given a filename.\n    \"\"\"\n    if utils.is_homepage(filename):\n        return 'Home'\n\n    title = os.path.splitext(filename)[0]\n    title = title.replace('-', ' ').replace('_', ' ')\n    # Captialize if the filename was all lowercase, otherwise leave it as-is.\n    if title.lower() == title:\n        title = title.capitalize()\n    return title\n\n\nclass SiteNavigation(object):\n    def __init__(self, pages_config, use_directory_urls=True):\n        self.url_context = URLContext()\n        self.file_context = FileContext()\n        self.nav_items, self.pages = \\\n            _generate_site_navigation(pages_config, self.url_context, use_directory_urls)\n        self.homepage = self.pages[0] if self.pages else None\n        self.use_directory_urls = use_directory_urls\n\n    def __str__(self):\n        return ''.join([str(item) for item in self])\n\n    def __iter__(self):\n        return iter(self.nav_items)\n\n    def walk_pages(self):\n        \"\"\"\n        Returns each page in the site in turn.\n\n        Additionally this sets the active status of the pages and headers,\n        in the site navigation, so that the rendered navbar can correctly\n        highlight the currently active page and/or header item.\n        \"\"\"\n        page = self.homepage\n        page.set_active()\n        self.url_context.set_current_url(page.abs_url)\n        self.file_context.set_current_path(page.input_path)\n        yield page\n        while page.next_page:\n            page.set_active(False)\n            page = page.next_page\n            page.set_active()\n            self.url_context.set_current_url(page.abs_url)\n            self.file_context.set_current_path(page.input_path)\n            yield page\n        page.set_active(False)\n\n    @property\n    def source_files(self):\n        if not hasattr(self, '_source_files'):\n            self._source_files = set([page.input_path for page in self.pages])\n        return self._source_files\n\n\nclass URLContext(object):\n    \"\"\"\n    The URLContext is used to ensure that we can generate the appropriate\n    relative URLs to other pages from any given page in the site.\n\n    We use relative URLs so that static sites can be deployed to any location\n    without having to specify what the path component on the host will be\n    if the documentation is not hosted at the root path.\n    \"\"\"\n\n    def __init__(self):\n        self.base_path = '/'\n\n    def set_current_url(self, current_url):\n        self.base_path = os.path.dirname(current_url)\n\n    def make_relative(self, url):\n        \"\"\"\n        Given a URL path return it as a relative URL,\n        given the context of the current page.\n        \"\"\"\n        suffix = '/' if (url.endswith('/') and len(url) > 1) else ''\n        # Workaround for bug on `os.path.relpath()` in Python 2.6\n        if self.base_path == '/':\n            if url == '/':\n                # Workaround for static assets\n                return '.'\n            return url.lstrip('/')\n        # Under Python 2.6, relative_path adds an extra '/' at the end.\n        relative_path = os.path.relpath(url, start=self.base_path).rstrip('/') + suffix\n\n        return utils.path_to_url(relative_path)\n\n\nclass FileContext(object):\n    \"\"\"\n    The FileContext is used to ensure that we can generate the appropriate\n    full path for other pages given their relative path from a particular page.\n\n    This is used when we have relative hyperlinks in the documentation, so that\n    we can ensure that they point to markdown documents that actually exist\n    in the `pages` config.\n    \"\"\"\n    def __init__(self):\n        self.current_file = None\n        self.base_path = ''\n\n    def set_current_path(self, current_path):\n        self.current_file = current_path\n        self.base_path = os.path.dirname(current_path)\n\n    def make_absolute(self, path):\n        \"\"\"\n        Given a relative file path return it as a POSIX-style\n        absolute filepath, given the context of the current page.\n        \"\"\"\n        return os.path.normpath(os.path.join(self.base_path, path))\n\n\nclass Page(object):\n    def __init__(self, title, url, path, url_context):\n        self.title = title\n        self.abs_url = url\n        self.active = False\n        self.url_context = url_context\n\n        # Relative paths to the input markdown file and output html file.\n        self.input_path = path\n        self.output_path = utils.get_html_path(path)\n\n        # Links to related pages\n        self.previous_page = None\n        self.next_page = None\n        self.ancestors = []\n\n    @property\n    def url(self):\n        return self.url_context.make_relative(self.abs_url)\n\n    @property\n    def is_homepage(self):\n        return utils.is_homepage(self.input_path)\n\n    def __str__(self):\n        return self._indent_print()\n\n    def _indent_print(self, depth=0):\n        indent = '    ' * depth\n        active_marker = ' [*]' if self.active else ''\n        title = self.title if (self.title is not None) else '[blank]'\n        return '%s%s - %s%s\\n' % (indent, title, self.abs_url, active_marker)\n\n    def set_active(self, active=True):\n        self.active = active\n        for ancestor in self.ancestors:\n            ancestor.active = active\n\n\nclass Header(object):\n    def __init__(self, title, children):\n        self.title, self.children = title, children\n        self.active = False\n\n    def __str__(self):\n        return self._indent_print()\n\n    def _indent_print(self, depth=0):\n        indent = '    ' * depth\n        active_marker = ' [*]' if self.active else ''\n        ret = '%s%s%s\\n' % (indent, self.title, active_marker)\n        for item in self.children:\n            ret += item._indent_print(depth + 1)\n        return ret\n\n\ndef _generate_site_navigation(pages_config, url_context, use_directory_urls=True):\n    \"\"\"\n    Returns a list of Page and Header instances that represent the\n    top level site navigation.\n    \"\"\"\n    nav_items = []\n    pages = []\n    previous = None\n\n    for config_line in pages_config:\n        if isinstance(config_line, str):\n            path = os.path.normpath(config_line)\n            title, child_title = None, None\n        elif len(config_line) in (1, 2, 3):\n            # Pad any items that don't exist with 'None'\n            padded_config = (list(config_line) + [None, None])[:3]\n            path, title, child_title = padded_config\n            path = os.path.normpath(path)\n        else:\n            msg = (\n                \"Line in 'page' config contained %d items.  \"\n                \"Expected 1, 2 or 3 strings.\" % len(config_line)\n            )\n            raise exceptions.ConfigurationError(msg)\n\n        # If both the title and child_title are None, then we\n        # have just been given a path. If that path contains a /\n        # then lets automatically nest it.\n        if title is None and child_title is None and os.path.sep in path:\n            filename = path.split(os.path.sep)[-1]\n            child_title = filename_to_title(filename)\n\n        if title is None:\n            filename = path.split(os.path.sep)[0]\n            title = filename_to_title(filename)\n\n        url = utils.get_url_path(path, use_directory_urls)\n\n        if not child_title:\n            # New top level page.\n            page = Page(title=title, url=url, path=path, url_context=url_context)\n            nav_items.append(page)\n        elif not nav_items or (nav_items[-1].title != title):\n            # New second level page.\n            page = Page(title=child_title, url=url, path=path, url_context=url_context)\n            header = Header(title=title, children=[page])\n            nav_items.append(header)\n            page.ancestors = [header]\n        else:\n            # Additional second level page.\n            page = Page(title=child_title, url=url, path=path, url_context=url_context)\n            header = nav_items[-1]\n            header.children.append(page)\n            page.ancestors = [header]\n\n        # Add in previous and next information.\n        if previous:\n            page.previous_page = previous\n            previous.next_page = page\n        previous = page\n\n        pages.append(page)\n\n    return (nav_items, pages)\n", "path": "mkdocs/nav.py"}], "after_files": [{"content": "# coding: utf-8\n\n\"\"\"\nDeals with generating the site-wide navigation.\n\nThis consists of building a set of interlinked page and header objects.\n\"\"\"\n\nimport logging\nimport os\n\nfrom mkdocs import utils, exceptions\n\nlog = logging.getLogger(__name__)\n\n\ndef filename_to_title(filename):\n    \"\"\"\n    Automatically generate a default title, given a filename.\n    \"\"\"\n    if utils.is_homepage(filename):\n        return 'Home'\n\n    title = os.path.splitext(filename)[0]\n    title = title.replace('-', ' ').replace('_', ' ')\n    # Captialize if the filename was all lowercase, otherwise leave it as-is.\n    if title.lower() == title:\n        title = title.capitalize()\n    return title\n\n\nclass SiteNavigation(object):\n    def __init__(self, pages_config, use_directory_urls=True):\n        self.url_context = URLContext()\n        self.file_context = FileContext()\n        self.nav_items, self.pages = \\\n            _generate_site_navigation(pages_config, self.url_context, use_directory_urls)\n        self.homepage = self.pages[0] if self.pages else None\n        self.use_directory_urls = use_directory_urls\n\n    def __str__(self):\n        return ''.join([str(item) for item in self])\n\n    def __iter__(self):\n        return iter(self.nav_items)\n\n    def walk_pages(self):\n        \"\"\"\n        Returns each page in the site in turn.\n\n        Additionally this sets the active status of the pages and headers,\n        in the site navigation, so that the rendered navbar can correctly\n        highlight the currently active page and/or header item.\n        \"\"\"\n        page = self.homepage\n        page.set_active()\n        self.url_context.set_current_url(page.abs_url)\n        self.file_context.set_current_path(page.input_path)\n        yield page\n        while page.next_page:\n            page.set_active(False)\n            page = page.next_page\n            page.set_active()\n            self.url_context.set_current_url(page.abs_url)\n            self.file_context.set_current_path(page.input_path)\n            yield page\n        page.set_active(False)\n\n    @property\n    def source_files(self):\n        if not hasattr(self, '_source_files'):\n            self._source_files = set([page.input_path for page in self.pages])\n        return self._source_files\n\n\nclass URLContext(object):\n    \"\"\"\n    The URLContext is used to ensure that we can generate the appropriate\n    relative URLs to other pages from any given page in the site.\n\n    We use relative URLs so that static sites can be deployed to any location\n    without having to specify what the path component on the host will be\n    if the documentation is not hosted at the root path.\n    \"\"\"\n\n    def __init__(self):\n        self.base_path = '/'\n\n    def set_current_url(self, current_url):\n        self.base_path = os.path.dirname(current_url)\n\n    def make_relative(self, url):\n        \"\"\"\n        Given a URL path return it as a relative URL,\n        given the context of the current page.\n        \"\"\"\n        suffix = '/' if (url.endswith('/') and len(url) > 1) else ''\n        # Workaround for bug on `os.path.relpath()` in Python 2.6\n        if self.base_path == '/':\n            if url == '/':\n                # Workaround for static assets\n                return '.'\n            return url.lstrip('/')\n        # Under Python 2.6, relative_path adds an extra '/' at the end.\n        relative_path = os.path.relpath(url, start=self.base_path).rstrip('/') + suffix\n\n        return utils.path_to_url(relative_path)\n\n\nclass FileContext(object):\n    \"\"\"\n    The FileContext is used to ensure that we can generate the appropriate\n    full path for other pages given their relative path from a particular page.\n\n    This is used when we have relative hyperlinks in the documentation, so that\n    we can ensure that they point to markdown documents that actually exist\n    in the `pages` config.\n    \"\"\"\n    def __init__(self):\n        self.current_file = None\n        self.base_path = ''\n\n    def set_current_path(self, current_path):\n        self.current_file = current_path\n        self.base_path = os.path.dirname(current_path)\n\n    def make_absolute(self, path):\n        \"\"\"\n        Given a relative file path return it as a POSIX-style\n        absolute filepath, given the context of the current page.\n        \"\"\"\n        return os.path.normpath(os.path.join(self.base_path, path))\n\n\nclass Page(object):\n    def __init__(self, title, url, path, url_context):\n        self.title = title\n        self.abs_url = url\n        self.active = False\n        self.url_context = url_context\n\n        # Relative paths to the input markdown file and output html file.\n        self.input_path = path\n        self.output_path = utils.get_html_path(path)\n\n        # Links to related pages\n        self.previous_page = None\n        self.next_page = None\n        self.ancestors = []\n\n    @property\n    def url(self):\n        return self.url_context.make_relative(self.abs_url)\n\n    @property\n    def is_homepage(self):\n        return utils.is_homepage(self.input_path)\n\n    def __str__(self):\n        return self._indent_print()\n\n    def _indent_print(self, depth=0):\n        indent = '    ' * depth\n        active_marker = ' [*]' if self.active else ''\n        title = self.title if (self.title is not None) else '[blank]'\n        return '%s%s - %s%s\\n' % (indent, title, self.abs_url, active_marker)\n\n    def set_active(self, active=True):\n        self.active = active\n        for ancestor in self.ancestors:\n            ancestor.active = active\n\n\nclass Header(object):\n    def __init__(self, title, children):\n        self.title, self.children = title, children\n        self.active = False\n\n    def __str__(self):\n        return self._indent_print()\n\n    def _indent_print(self, depth=0):\n        indent = '    ' * depth\n        active_marker = ' [*]' if self.active else ''\n        ret = '%s%s%s\\n' % (indent, self.title, active_marker)\n        for item in self.children:\n            ret += item._indent_print(depth + 1)\n        return ret\n\n\ndef _generate_site_navigation(pages_config, url_context, use_directory_urls=True):\n    \"\"\"\n    Returns a list of Page and Header instances that represent the\n    top level site navigation.\n    \"\"\"\n    nav_items = []\n    pages = []\n    previous = None\n\n    for config_line in pages_config:\n        if isinstance(config_line, str):\n            path = os.path.normpath(config_line)\n            title, child_title = None, None\n        elif len(config_line) in (1, 2, 3):\n            # Pad any items that don't exist with 'None'\n            padded_config = (list(config_line) + [None, None])[:3]\n            path, title, child_title = padded_config\n            path = os.path.normpath(path)\n        else:\n            msg = (\n                \"Line in 'page' config contained %d items.  \"\n                \"Expected 1, 2 or 3 strings.\" % len(config_line)\n            )\n            raise exceptions.ConfigurationError(msg)\n\n        # If both the title and child_title are None, then we\n        # have just been given a path. If that path contains a /\n        # then lets automatically nest it.\n        if title is None and child_title is None and os.path.sep in path:\n            filename = path.split(os.path.sep)[-1]\n            child_title = filename_to_title(filename)\n\n        if title is None:\n            filename = path.split(os.path.sep)[0]\n            title = filename_to_title(filename)\n\n        # If we don't have a child title but the other title is the same, we\n        # should be within a section and the child title needs to be inferred\n        # from the filename.\n        if len(nav_items) and title == nav_items[-1].title == title and child_title is None:\n            filename = path.split(os.path.sep)[-1]\n            child_title = filename_to_title(filename)\n\n        url = utils.get_url_path(path, use_directory_urls)\n\n        if not child_title:\n            # New top level page.\n            page = Page(title=title, url=url, path=path, url_context=url_context)\n            nav_items.append(page)\n        elif not nav_items or (nav_items[-1].title != title):\n            # New second level page.\n            page = Page(title=child_title, url=url, path=path, url_context=url_context)\n            header = Header(title=title, children=[page])\n            nav_items.append(header)\n            page.ancestors = [header]\n        else:\n            # Additional second level page.\n            page = Page(title=child_title, url=url, path=path, url_context=url_context)\n            header = nav_items[-1]\n            header.children.append(page)\n            page.ancestors = [header]\n\n        # Add in previous and next information.\n        if previous:\n            page.previous_page = previous\n            previous.next_page = page\n        previous = page\n\n        pages.append(page)\n\n    return (nav_items, pages)\n", "path": "mkdocs/nav.py"}]}