We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Wrong paths to extra media files
Incorrect paths are generated for files in `extra_css` and `extra_javascript`. For example, `test.js` will be referenced on the index page as `./test.js`, on the next page as `.././test.js`, on the next page as `../.././test.js`, etc.


--- 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/build.py`
Content:
```
1 # coding: utf-8
2 from __future__ import print_function
3 
4 from mkdocs import nav, toc, utils
5 from mkdocs.compat import urljoin, urlparse, urlunparse, PY2
6 import jinja2
7 import markdown
8 import os
9 import re
10 
11 
12 class PathToURL(object):
13     def __init__(self, nav=None):
14         self.nav = nav
15 
16     def __call__(self, match):
17         url = match.groups()[0]
18         scheme, netloc, path, query, query, fragment = urlparse(url)
19 
20         if (scheme or netloc or not utils.is_markdown_file(path)):
21             # Ignore URLs unless they are a relative link to a markdown file.
22             return 'a href="%s"' % url
23 
24         if self.nav:
25             # If the site navigation has been provided, then validate
26             # the internal hyperlink, making sure the target actually exists.
27             target_file = self.nav.file_context.make_absolute(path)
28             if target_file not in self.nav.source_files:
29                 source_file = self.nav.file_context.current_file
30                 msg = (
31                     'The page "%s" contained a hyperlink to "%s" which '
32                     'is not listed in the "pages" configuration.'
33                 )
34                 assert False, msg % (source_file, target_file)
35             path = utils.get_url_path(target_file)
36             path = self.nav.url_context.make_relative(path)
37         else:
38             path = utils.get_url_path(path).lstrip('/')
39 
40         # Convert the .md hyperlink to a relative hyperlink to the HTML page.
41         url = urlunparse((scheme, netloc, path, query, query, fragment))
42         return 'a href="%s"' % url
43 
44 
45 def convert_markdown(markdown_source, extensions=()):
46     """
47     Convert the Markdown source file to HTML content, and additionally
48     return the parsed table of contents, and a dictionary of any metadata
49     that was specified in the Markdown file.
50 
51     `extensions` is an optional sequence of Python Markdown extensions to add
52     to the default set.
53     """
54 
55     # Prepend a table of contents marker for the TOC extension
56     markdown_source = toc.pre_process(markdown_source)
57 
58     # Generate the HTML from the markdown source
59     md = markdown.Markdown(
60         extensions=['meta', 'toc', 'tables', 'fenced_code'] + list(extensions)
61     )
62     html_content = md.convert(markdown_source)
63     meta = md.Meta
64 
65     # Strip out the generated table of contents
66     (html_content, toc_html) = toc.post_process(html_content)
67 
68     # Post process the generated table of contents into a data structure
69     table_of_contents = toc.TableOfContents(toc_html)
70 
71     return (html_content, table_of_contents, meta)
72 
73 
74 def post_process_html(html_content, nav=None):
75     html_content = re.sub(r'a href="([^"]*)"', PathToURL(nav), html_content)
76     html_content = re.sub('<pre>', '<pre class="prettyprint well">', html_content)
77     return html_content
78 
79 
80 def get_context(page, content, nav, toc, meta, config):
81     site_name = config['site_name']
82 
83     if page.is_homepage or page.title is None:
84         page_title = site_name
85     else:
86         page_title = page.title + ' - ' + site_name
87 
88     if page.is_homepage:
89         page_description = config['site_description']
90     else:
91         page_description = None
92 
93     if config['site_url']:
94         base = config['site_url']
95         if not base.endswith('/'):
96             base += '/'
97         canonical_url = urljoin(base, page.abs_url.lstrip('/'))
98     else:
99         canonical_url = None
100 
101     if config['site_favicon']:
102         site_favicon = nav.url_context.make_relative('/' + config['site_favicon'])
103     else:
104         site_favicon = None
105 
106     if config['extra_javascript']:
107         config['extra_javascript'] = utils.create_media_urls(nav=nav, url_list=config['extra_javascript'])
108 
109     if config['extra_css']:
110         config['extra_css'] = utils.create_media_urls(nav=nav, url_list=config['extra_css'])
111 
112     return {
113         'site_name': site_name,
114         'site_author': config['site_author'],
115         'favicon': site_favicon,
116 
117         'page_title': page_title,
118         'page_description': page_description,
119 
120         'content': content,
121         'toc': toc,
122         'nav': nav,
123         'meta': meta,
124 
125         'base_url': nav.url_context.make_relative('/'),
126         'homepage_url': nav.homepage.url,
127         'canonical_url': canonical_url,
128 
129         'current_page': page,
130         'previous_page': page.previous_page,
131         'next_page': page.next_page,
132 
133         # Note that there's intentionally repetition here. Rather than simply
134         # provide the config dictionary we instead pass everything explicitly.
135         #
136         # This helps ensure that we can throughly document the context that
137         # gets passed to themes.
138         'repo_url': config['repo_url'],
139         'repo_name': config['repo_name'],
140 
141         'extra_css': config['extra_css'],
142         'extra_javascript': config['extra_javascript'],
143 
144         'include_nav': config['include_nav'],
145         'include_next_prev': config['include_next_prev'],
146         'include_search': config['include_search'],
147 
148         'copyright': config['copyright'],
149         'google-analytics': config['google-analytics']
150     }
151 
152 
153 def build_pages(config):
154     """
155     Builds all the pages and writes them into the build directory.
156     """
157     site_navigation = nav.SiteNavigation(config['pages'])
158     loader = jinja2.FileSystemLoader(config['theme_dir'])
159     env = jinja2.Environment(loader=loader)
160 
161     for page in site_navigation.walk_pages():
162         # Read the input file
163         input_path = os.path.join(config['docs_dir'], page.input_path)
164         input_content = open(input_path, 'r').read()
165         if PY2:
166             input_content = input_content.decode('utf-8')
167 
168         # Process the markdown text
169         html_content, table_of_contents, meta = convert_markdown(
170             input_content, extensions=config['markdown_extensions']
171         )
172         html_content = post_process_html(html_content, site_navigation)
173 
174         context = get_context(
175             page, html_content, site_navigation,
176             table_of_contents, meta, config
177         )
178 
179         # Allow 'template:' override in md source files.
180         if 'template' in meta:
181             template = env.get_template(meta['template'][0])
182         else:
183             template = env.get_template('base.html')
184 
185         # Render the template.
186         output_content = template.render(context)
187 
188         # Write the output file.
189         output_path = os.path.join(config['site_dir'], page.output_path)
190         utils.write_file(output_content.encode('utf-8'), output_path)
191 
192 
193 def build(config, live_server=False):
194     """
195     Perform a full site build.
196     """
197     if not live_server:
198         print("Building documentation to directory: %s" % config['site_dir'])
199     utils.copy_media_files(config['theme_dir'], config['site_dir'])
200     utils.copy_media_files(config['docs_dir'], config['site_dir'])
201     build_pages(config)
202
```
--- 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/build.py b/mkdocs/build.py
--- a/mkdocs/build.py
+++ b/mkdocs/build.py
@@ -103,11 +103,9 @@
     else:
         site_favicon = None
 
-    if config['extra_javascript']:
-        config['extra_javascript'] = utils.create_media_urls(nav=nav, url_list=config['extra_javascript'])
+    extra_javascript = utils.create_media_urls(nav=nav, url_list=config['extra_javascript'])
 
-    if config['extra_css']:
-        config['extra_css'] = utils.create_media_urls(nav=nav, url_list=config['extra_css'])
+    extra_css = utils.create_media_urls(nav=nav, url_list=config['extra_css'])
 
     return {
         'site_name': site_name,
@@ -138,8 +136,8 @@
         'repo_url': config['repo_url'],
         'repo_name': config['repo_name'],
 
-        'extra_css': config['extra_css'],
-        'extra_javascript': config['extra_javascript'],
+        'extra_css': extra_css,
+        'extra_javascript': extra_javascript,
 
         'include_nav': config['include_nav'],
         'include_next_prev': config['include_next_prev'],

{"golden_diff": "diff --git a/mkdocs/build.py b/mkdocs/build.py\n--- a/mkdocs/build.py\n+++ b/mkdocs/build.py\n@@ -103,11 +103,9 @@\n     else:\n         site_favicon = None\n \n-    if config['extra_javascript']:\n-        config['extra_javascript'] = utils.create_media_urls(nav=nav, url_list=config['extra_javascript'])\n+    extra_javascript = utils.create_media_urls(nav=nav, url_list=config['extra_javascript'])\n \n-    if config['extra_css']:\n-        config['extra_css'] = utils.create_media_urls(nav=nav, url_list=config['extra_css'])\n+    extra_css = utils.create_media_urls(nav=nav, url_list=config['extra_css'])\n \n     return {\n         'site_name': site_name,\n@@ -138,8 +136,8 @@\n         'repo_url': config['repo_url'],\n         'repo_name': config['repo_name'],\n \n-        'extra_css': config['extra_css'],\n-        'extra_javascript': config['extra_javascript'],\n+        'extra_css': extra_css,\n+        'extra_javascript': extra_javascript,\n \n         'include_nav': config['include_nav'],\n         'include_next_prev': config['include_next_prev'],\n", "issue": "Wrong paths to extra media files\nIncorrect paths are generated for files in `extra_css` and `extra_javascript`. For example, `test.js` will be referenced on the index page as `./test.js`, on the next page as `.././test.js`, on the next page as `../.././test.js`, etc.\n\n", "before_files": [{"content": "# coding: utf-8\nfrom __future__ import print_function\n\nfrom mkdocs import nav, toc, utils\nfrom mkdocs.compat import urljoin, urlparse, urlunparse, PY2\nimport jinja2\nimport markdown\nimport os\nimport re\n\n\nclass PathToURL(object):\n    def __init__(self, nav=None):\n        self.nav = nav\n\n    def __call__(self, match):\n        url = match.groups()[0]\n        scheme, netloc, path, query, query, fragment = urlparse(url)\n\n        if (scheme or netloc or not utils.is_markdown_file(path)):\n            # Ignore URLs unless they are a relative link to a markdown file.\n            return 'a href=\"%s\"' % url\n\n        if self.nav:\n            # If the site navigation has been provided, then validate\n            # the internal hyperlink, making sure the target actually exists.\n            target_file = self.nav.file_context.make_absolute(path)\n            if target_file not in self.nav.source_files:\n                source_file = self.nav.file_context.current_file\n                msg = (\n                    'The page \"%s\" contained a hyperlink to \"%s\" which '\n                    'is not listed in the \"pages\" configuration.'\n                )\n                assert False, msg % (source_file, target_file)\n            path = utils.get_url_path(target_file)\n            path = self.nav.url_context.make_relative(path)\n        else:\n            path = utils.get_url_path(path).lstrip('/')\n\n        # Convert the .md hyperlink to a relative hyperlink to the HTML page.\n        url = urlunparse((scheme, netloc, path, query, query, fragment))\n        return 'a href=\"%s\"' % url\n\n\ndef convert_markdown(markdown_source, extensions=()):\n    \"\"\"\n    Convert the Markdown source file to HTML content, and additionally\n    return the parsed table of contents, and a dictionary of any metadata\n    that was specified in the Markdown file.\n\n    `extensions` is an optional sequence of Python Markdown extensions to add\n    to the default set.\n    \"\"\"\n\n    # Prepend a table of contents marker for the TOC extension\n    markdown_source = toc.pre_process(markdown_source)\n\n    # Generate the HTML from the markdown source\n    md = markdown.Markdown(\n        extensions=['meta', 'toc', 'tables', 'fenced_code'] + list(extensions)\n    )\n    html_content = md.convert(markdown_source)\n    meta = md.Meta\n\n    # Strip out the generated table of contents\n    (html_content, toc_html) = toc.post_process(html_content)\n\n    # Post process the generated table of contents into a data structure\n    table_of_contents = toc.TableOfContents(toc_html)\n\n    return (html_content, table_of_contents, meta)\n\n\ndef post_process_html(html_content, nav=None):\n    html_content = re.sub(r'a href=\"([^\"]*)\"', PathToURL(nav), html_content)\n    html_content = re.sub('<pre>', '<pre class=\"prettyprint well\">', html_content)\n    return html_content\n\n\ndef get_context(page, content, nav, toc, meta, config):\n    site_name = config['site_name']\n\n    if page.is_homepage or page.title is None:\n        page_title = site_name\n    else:\n        page_title = page.title + ' - ' + site_name\n\n    if page.is_homepage:\n        page_description = config['site_description']\n    else:\n        page_description = None\n\n    if config['site_url']:\n        base = config['site_url']\n        if not base.endswith('/'):\n            base += '/'\n        canonical_url = urljoin(base, page.abs_url.lstrip('/'))\n    else:\n        canonical_url = None\n\n    if config['site_favicon']:\n        site_favicon = nav.url_context.make_relative('/' + config['site_favicon'])\n    else:\n        site_favicon = None\n\n    if config['extra_javascript']:\n        config['extra_javascript'] = utils.create_media_urls(nav=nav, url_list=config['extra_javascript'])\n\n    if config['extra_css']:\n        config['extra_css'] = utils.create_media_urls(nav=nav, url_list=config['extra_css'])\n\n    return {\n        'site_name': site_name,\n        'site_author': config['site_author'],\n        'favicon': site_favicon,\n\n        'page_title': page_title,\n        'page_description': page_description,\n\n        'content': content,\n        'toc': toc,\n        'nav': nav,\n        'meta': meta,\n\n        'base_url': nav.url_context.make_relative('/'),\n        'homepage_url': nav.homepage.url,\n        'canonical_url': canonical_url,\n\n        'current_page': page,\n        'previous_page': page.previous_page,\n        'next_page': page.next_page,\n\n        # Note that there's intentionally repetition here. Rather than simply\n        # provide the config dictionary we instead pass everything explicitly.\n        #\n        # This helps ensure that we can throughly document the context that\n        # gets passed to themes.\n        'repo_url': config['repo_url'],\n        'repo_name': config['repo_name'],\n\n        'extra_css': config['extra_css'],\n        'extra_javascript': config['extra_javascript'],\n\n        'include_nav': config['include_nav'],\n        'include_next_prev': config['include_next_prev'],\n        'include_search': config['include_search'],\n\n        'copyright': config['copyright'],\n        'google-analytics': config['google-analytics']\n    }\n\n\ndef build_pages(config):\n    \"\"\"\n    Builds all the pages and writes them into the build directory.\n    \"\"\"\n    site_navigation = nav.SiteNavigation(config['pages'])\n    loader = jinja2.FileSystemLoader(config['theme_dir'])\n    env = jinja2.Environment(loader=loader)\n\n    for page in site_navigation.walk_pages():\n        # Read the input file\n        input_path = os.path.join(config['docs_dir'], page.input_path)\n        input_content = open(input_path, 'r').read()\n        if PY2:\n            input_content = input_content.decode('utf-8')\n\n        # Process the markdown text\n        html_content, table_of_contents, meta = convert_markdown(\n            input_content, extensions=config['markdown_extensions']\n        )\n        html_content = post_process_html(html_content, site_navigation)\n\n        context = get_context(\n            page, html_content, site_navigation,\n            table_of_contents, meta, config\n        )\n\n        # Allow 'template:' override in md source files.\n        if 'template' in meta:\n            template = env.get_template(meta['template'][0])\n        else:\n            template = env.get_template('base.html')\n\n        # Render the template.\n        output_content = template.render(context)\n\n        # Write the output file.\n        output_path = os.path.join(config['site_dir'], page.output_path)\n        utils.write_file(output_content.encode('utf-8'), output_path)\n\n\ndef build(config, live_server=False):\n    \"\"\"\n    Perform a full site build.\n    \"\"\"\n    if not live_server:\n        print(\"Building documentation to directory: %s\" % config['site_dir'])\n    utils.copy_media_files(config['theme_dir'], config['site_dir'])\n    utils.copy_media_files(config['docs_dir'], config['site_dir'])\n    build_pages(config)\n", "path": "mkdocs/build.py"}], "after_files": [{"content": "# coding: utf-8\nfrom __future__ import print_function\n\nfrom mkdocs import nav, toc, utils\nfrom mkdocs.compat import urljoin, urlparse, urlunparse, PY2\nimport jinja2\nimport markdown\nimport os\nimport re\n\n\nclass PathToURL(object):\n    def __init__(self, nav=None):\n        self.nav = nav\n\n    def __call__(self, match):\n        url = match.groups()[0]\n        scheme, netloc, path, query, query, fragment = urlparse(url)\n\n        if (scheme or netloc or not utils.is_markdown_file(path)):\n            # Ignore URLs unless they are a relative link to a markdown file.\n            return 'a href=\"%s\"' % url\n\n        if self.nav:\n            # If the site navigation has been provided, then validate\n            # the internal hyperlink, making sure the target actually exists.\n            target_file = self.nav.file_context.make_absolute(path)\n            if target_file not in self.nav.source_files:\n                source_file = self.nav.file_context.current_file\n                msg = (\n                    'The page \"%s\" contained a hyperlink to \"%s\" which '\n                    'is not listed in the \"pages\" configuration.'\n                )\n                assert False, msg % (source_file, target_file)\n            path = utils.get_url_path(target_file)\n            path = self.nav.url_context.make_relative(path)\n        else:\n            path = utils.get_url_path(path).lstrip('/')\n\n        # Convert the .md hyperlink to a relative hyperlink to the HTML page.\n        url = urlunparse((scheme, netloc, path, query, query, fragment))\n        return 'a href=\"%s\"' % url\n\n\ndef convert_markdown(markdown_source, extensions=()):\n    \"\"\"\n    Convert the Markdown source file to HTML content, and additionally\n    return the parsed table of contents, and a dictionary of any metadata\n    that was specified in the Markdown file.\n\n    `extensions` is an optional sequence of Python Markdown extensions to add\n    to the default set.\n    \"\"\"\n\n    # Prepend a table of contents marker for the TOC extension\n    markdown_source = toc.pre_process(markdown_source)\n\n    # Generate the HTML from the markdown source\n    md = markdown.Markdown(\n        extensions=['meta', 'toc', 'tables', 'fenced_code'] + list(extensions)\n    )\n    html_content = md.convert(markdown_source)\n    meta = md.Meta\n\n    # Strip out the generated table of contents\n    (html_content, toc_html) = toc.post_process(html_content)\n\n    # Post process the generated table of contents into a data structure\n    table_of_contents = toc.TableOfContents(toc_html)\n\n    return (html_content, table_of_contents, meta)\n\n\ndef post_process_html(html_content, nav=None):\n    html_content = re.sub(r'a href=\"([^\"]*)\"', PathToURL(nav), html_content)\n    html_content = re.sub('<pre>', '<pre class=\"prettyprint well\">', html_content)\n    return html_content\n\n\ndef get_context(page, content, nav, toc, meta, config):\n    site_name = config['site_name']\n\n    if page.is_homepage or page.title is None:\n        page_title = site_name\n    else:\n        page_title = page.title + ' - ' + site_name\n\n    if page.is_homepage:\n        page_description = config['site_description']\n    else:\n        page_description = None\n\n    if config['site_url']:\n        base = config['site_url']\n        if not base.endswith('/'):\n            base += '/'\n        canonical_url = urljoin(base, page.abs_url.lstrip('/'))\n    else:\n        canonical_url = None\n\n    if config['site_favicon']:\n        site_favicon = nav.url_context.make_relative('/' + config['site_favicon'])\n    else:\n        site_favicon = None\n\n    extra_javascript = utils.create_media_urls(nav=nav, url_list=config['extra_javascript'])\n\n    extra_css = utils.create_media_urls(nav=nav, url_list=config['extra_css'])\n\n    return {\n        'site_name': site_name,\n        'site_author': config['site_author'],\n        'favicon': site_favicon,\n\n        'page_title': page_title,\n        'page_description': page_description,\n\n        'content': content,\n        'toc': toc,\n        'nav': nav,\n        'meta': meta,\n\n        'base_url': nav.url_context.make_relative('/'),\n        'homepage_url': nav.homepage.url,\n        'canonical_url': canonical_url,\n\n        'current_page': page,\n        'previous_page': page.previous_page,\n        'next_page': page.next_page,\n\n        # Note that there's intentionally repetition here. Rather than simply\n        # provide the config dictionary we instead pass everything explicitly.\n        #\n        # This helps ensure that we can throughly document the context that\n        # gets passed to themes.\n        'repo_url': config['repo_url'],\n        'repo_name': config['repo_name'],\n\n        'extra_css': extra_css,\n        'extra_javascript': extra_javascript,\n\n        'include_nav': config['include_nav'],\n        'include_next_prev': config['include_next_prev'],\n        'include_search': config['include_search'],\n\n        'copyright': config['copyright'],\n        'google-analytics': config['google-analytics']\n    }\n\n\ndef build_pages(config):\n    \"\"\"\n    Builds all the pages and writes them into the build directory.\n    \"\"\"\n    site_navigation = nav.SiteNavigation(config['pages'])\n    loader = jinja2.FileSystemLoader(config['theme_dir'])\n    env = jinja2.Environment(loader=loader)\n\n    for page in site_navigation.walk_pages():\n        # Read the input file\n        input_path = os.path.join(config['docs_dir'], page.input_path)\n        input_content = open(input_path, 'r').read()\n        if PY2:\n            input_content = input_content.decode('utf-8')\n\n        # Process the markdown text\n        html_content, table_of_contents, meta = convert_markdown(\n            input_content, extensions=config['markdown_extensions']\n        )\n        html_content = post_process_html(html_content, site_navigation)\n\n        context = get_context(\n            page, html_content, site_navigation,\n            table_of_contents, meta, config\n        )\n\n        # Allow 'template:' override in md source files.\n        if 'template' in meta:\n            template = env.get_template(meta['template'][0])\n        else:\n            template = env.get_template('base.html')\n\n        # Render the template.\n        output_content = template.render(context)\n\n        # Write the output file.\n        output_path = os.path.join(config['site_dir'], page.output_path)\n        utils.write_file(output_content.encode('utf-8'), output_path)\n\n\ndef build(config, live_server=False):\n    \"\"\"\n    Perform a full site build.\n    \"\"\"\n    if not live_server:\n        print(\"Building documentation to directory: %s\" % config['site_dir'])\n    utils.copy_media_files(config['theme_dir'], config['site_dir'])\n    utils.copy_media_files(config['docs_dir'], config['site_dir'])\n    build_pages(config)\n", "path": "mkdocs/build.py"}]}