We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Broken links/css in readthedocs 404 page 
The [404.html](https://github.com/mkdocs/mkdocs/blob/master/mkdocs/themes/readthedocs/404.html) added in 0.17.0 seems to have broken links and css ([failing CI build](https://travis-ci.org/opensciencegrid/docs/builds/290469999?utm_source=github_status&utm_medium=notification)). The links in the generated `404.html` file all start with a `docs/...` prefix but when I inspect the `site` dir after a `mkdocs build`, there is no `docs` directory.

--- 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/commands/serve.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 import logging
4 import shutil
5 import tempfile
6 
7 from os.path import isfile, join
8 from mkdocs.commands.build import build
9 from mkdocs.config import load_config
10 
11 log = logging.getLogger(__name__)
12 
13 
14 def _get_handler(site_dir, StaticFileHandler):
15 
16     from tornado.template import Loader
17 
18     class WebHandler(StaticFileHandler):
19 
20         def write_error(self, status_code, **kwargs):
21 
22             if status_code in (404, 500):
23                 error_page = '{}.html'.format(status_code)
24                 if isfile(join(site_dir, error_page)):
25                     self.write(Loader(site_dir).load(error_page).generate())
26                 else:
27                     super(WebHandler, self).write_error(status_code, **kwargs)
28 
29     return WebHandler
30 
31 
32 def _livereload(host, port, config, builder, site_dir):
33 
34     # We are importing here for anyone that has issues with livereload. Even if
35     # this fails, the --no-livereload alternative should still work.
36     from livereload import Server
37     import livereload.handlers
38 
39     class LiveReloadServer(Server):
40 
41         def get_web_handlers(self, script):
42             handlers = super(LiveReloadServer, self).get_web_handlers(script)
43             # replace livereload handler
44             return [(handlers[0][0], _get_handler(site_dir, livereload.handlers.StaticFileHandler), handlers[0][2],)]
45 
46     server = LiveReloadServer()
47 
48     # Watch the documentation files, the config file and the theme files.
49     server.watch(config['docs_dir'], builder)
50     server.watch(config['config_file_path'], builder)
51 
52     for d in config['theme'].dirs:
53         server.watch(d, builder)
54 
55     # Run `serve` plugin events.
56     server = config['plugins'].run_event('serve', server, config=config)
57 
58     server.serve(root=site_dir, host=host, port=port, restart_delay=0)
59 
60 
61 def _static_server(host, port, site_dir):
62 
63     # Importing here to seperate the code paths from the --livereload
64     # alternative.
65     from tornado import ioloop
66     from tornado import web
67 
68     application = web.Application([
69         (r"/(.*)", _get_handler(site_dir, web.StaticFileHandler), {
70             "path": site_dir,
71             "default_filename": "index.html"
72         }),
73     ])
74     application.listen(port=port, address=host)
75 
76     log.info('Running at: http://%s:%s/', host, port)
77     log.info('Hold ctrl+c to quit.')
78     try:
79         ioloop.IOLoop.instance().start()
80     except KeyboardInterrupt:
81         log.info('Stopping server...')
82 
83 
84 def serve(config_file=None, dev_addr=None, strict=None, theme=None,
85           theme_dir=None, livereload='livereload'):
86     """
87     Start the MkDocs development server
88 
89     By default it will serve the documentation on http://localhost:8000/ and
90     it will rebuild the documentation and refresh the page automatically
91     whenever a file is edited.
92     """
93 
94     # Create a temporary build directory, and set some options to serve it
95     tempdir = tempfile.mkdtemp()
96 
97     def builder():
98         log.info("Building documentation...")
99         config = load_config(
100             config_file=config_file,
101             dev_addr=dev_addr,
102             strict=strict,
103             theme=theme,
104             theme_dir=theme_dir
105         )
106         config['site_dir'] = tempdir
107         live_server = livereload in ['dirty', 'livereload']
108         dirty = livereload == 'dirty'
109         build(config, live_server=live_server, dirty=dirty)
110         return config
111 
112     try:
113         # Perform the initial build
114         config = builder()
115 
116         host, port = config['dev_addr']
117 
118         if livereload in ['livereload', 'dirty']:
119             _livereload(host, port, config, builder, tempdir)
120         else:
121             _static_server(host, port, tempdir)
122     finally:
123         shutil.rmtree(tempdir)
124
```
--- 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/commands/serve.py b/mkdocs/commands/serve.py
--- a/mkdocs/commands/serve.py
+++ b/mkdocs/commands/serve.py
@@ -103,7 +103,10 @@
             theme=theme,
             theme_dir=theme_dir
         )
+        # Override a few config settings after validation
         config['site_dir'] = tempdir
+        config['site_url'] = 'http://{0}/'.format(config['dev_addr'])
+
         live_server = livereload in ['dirty', 'livereload']
         dirty = livereload == 'dirty'
         build(config, live_server=live_server, dirty=dirty)

{"golden_diff": "diff --git a/mkdocs/commands/serve.py b/mkdocs/commands/serve.py\n--- a/mkdocs/commands/serve.py\n+++ b/mkdocs/commands/serve.py\n@@ -103,7 +103,10 @@\n             theme=theme,\n             theme_dir=theme_dir\n         )\n+        # Override a few config settings after validation\n         config['site_dir'] = tempdir\n+        config['site_url'] = 'http://{0}/'.format(config['dev_addr'])\n+\n         live_server = livereload in ['dirty', 'livereload']\n         dirty = livereload == 'dirty'\n         build(config, live_server=live_server, dirty=dirty)\n", "issue": "Broken links/css in readthedocs 404 page \nThe [404.html](https://github.com/mkdocs/mkdocs/blob/master/mkdocs/themes/readthedocs/404.html) added in 0.17.0 seems to have broken links and css ([failing CI build](https://travis-ci.org/opensciencegrid/docs/builds/290469999?utm_source=github_status&utm_medium=notification)). The links in the generated `404.html` file all start with a `docs/...` prefix but when I inspect the `site` dir after a `mkdocs build`, there is no `docs` directory.\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport logging\nimport shutil\nimport tempfile\n\nfrom os.path import isfile, join\nfrom mkdocs.commands.build import build\nfrom mkdocs.config import load_config\n\nlog = logging.getLogger(__name__)\n\n\ndef _get_handler(site_dir, StaticFileHandler):\n\n    from tornado.template import Loader\n\n    class WebHandler(StaticFileHandler):\n\n        def write_error(self, status_code, **kwargs):\n\n            if status_code in (404, 500):\n                error_page = '{}.html'.format(status_code)\n                if isfile(join(site_dir, error_page)):\n                    self.write(Loader(site_dir).load(error_page).generate())\n                else:\n                    super(WebHandler, self).write_error(status_code, **kwargs)\n\n    return WebHandler\n\n\ndef _livereload(host, port, config, builder, site_dir):\n\n    # We are importing here for anyone that has issues with livereload. Even if\n    # this fails, the --no-livereload alternative should still work.\n    from livereload import Server\n    import livereload.handlers\n\n    class LiveReloadServer(Server):\n\n        def get_web_handlers(self, script):\n            handlers = super(LiveReloadServer, self).get_web_handlers(script)\n            # replace livereload handler\n            return [(handlers[0][0], _get_handler(site_dir, livereload.handlers.StaticFileHandler), handlers[0][2],)]\n\n    server = LiveReloadServer()\n\n    # Watch the documentation files, the config file and the theme files.\n    server.watch(config['docs_dir'], builder)\n    server.watch(config['config_file_path'], builder)\n\n    for d in config['theme'].dirs:\n        server.watch(d, builder)\n\n    # Run `serve` plugin events.\n    server = config['plugins'].run_event('serve', server, config=config)\n\n    server.serve(root=site_dir, host=host, port=port, restart_delay=0)\n\n\ndef _static_server(host, port, site_dir):\n\n    # Importing here to seperate the code paths from the --livereload\n    # alternative.\n    from tornado import ioloop\n    from tornado import web\n\n    application = web.Application([\n        (r\"/(.*)\", _get_handler(site_dir, web.StaticFileHandler), {\n            \"path\": site_dir,\n            \"default_filename\": \"index.html\"\n        }),\n    ])\n    application.listen(port=port, address=host)\n\n    log.info('Running at: http://%s:%s/', host, port)\n    log.info('Hold ctrl+c to quit.')\n    try:\n        ioloop.IOLoop.instance().start()\n    except KeyboardInterrupt:\n        log.info('Stopping server...')\n\n\ndef serve(config_file=None, dev_addr=None, strict=None, theme=None,\n          theme_dir=None, livereload='livereload'):\n    \"\"\"\n    Start the MkDocs development server\n\n    By default it will serve the documentation on http://localhost:8000/ and\n    it will rebuild the documentation and refresh the page automatically\n    whenever a file is edited.\n    \"\"\"\n\n    # Create a temporary build directory, and set some options to serve it\n    tempdir = tempfile.mkdtemp()\n\n    def builder():\n        log.info(\"Building documentation...\")\n        config = load_config(\n            config_file=config_file,\n            dev_addr=dev_addr,\n            strict=strict,\n            theme=theme,\n            theme_dir=theme_dir\n        )\n        config['site_dir'] = tempdir\n        live_server = livereload in ['dirty', 'livereload']\n        dirty = livereload == 'dirty'\n        build(config, live_server=live_server, dirty=dirty)\n        return config\n\n    try:\n        # Perform the initial build\n        config = builder()\n\n        host, port = config['dev_addr']\n\n        if livereload in ['livereload', 'dirty']:\n            _livereload(host, port, config, builder, tempdir)\n        else:\n            _static_server(host, port, tempdir)\n    finally:\n        shutil.rmtree(tempdir)\n", "path": "mkdocs/commands/serve.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport logging\nimport shutil\nimport tempfile\n\nfrom os.path import isfile, join\nfrom mkdocs.commands.build import build\nfrom mkdocs.config import load_config\n\nlog = logging.getLogger(__name__)\n\n\ndef _get_handler(site_dir, StaticFileHandler):\n\n    from tornado.template import Loader\n\n    class WebHandler(StaticFileHandler):\n\n        def write_error(self, status_code, **kwargs):\n\n            if status_code in (404, 500):\n                error_page = '{}.html'.format(status_code)\n                if isfile(join(site_dir, error_page)):\n                    self.write(Loader(site_dir).load(error_page).generate())\n                else:\n                    super(WebHandler, self).write_error(status_code, **kwargs)\n\n    return WebHandler\n\n\ndef _livereload(host, port, config, builder, site_dir):\n\n    # We are importing here for anyone that has issues with livereload. Even if\n    # this fails, the --no-livereload alternative should still work.\n    from livereload import Server\n    import livereload.handlers\n\n    class LiveReloadServer(Server):\n\n        def get_web_handlers(self, script):\n            handlers = super(LiveReloadServer, self).get_web_handlers(script)\n            # replace livereload handler\n            return [(handlers[0][0], _get_handler(site_dir, livereload.handlers.StaticFileHandler), handlers[0][2],)]\n\n    server = LiveReloadServer()\n\n    # Watch the documentation files, the config file and the theme files.\n    server.watch(config['docs_dir'], builder)\n    server.watch(config['config_file_path'], builder)\n\n    for d in config['theme'].dirs:\n        server.watch(d, builder)\n\n    # Run `serve` plugin events.\n    server = config['plugins'].run_event('serve', server, config=config)\n\n    server.serve(root=site_dir, host=host, port=port, restart_delay=0)\n\n\ndef _static_server(host, port, site_dir):\n\n    # Importing here to seperate the code paths from the --livereload\n    # alternative.\n    from tornado import ioloop\n    from tornado import web\n\n    application = web.Application([\n        (r\"/(.*)\", _get_handler(site_dir, web.StaticFileHandler), {\n            \"path\": site_dir,\n            \"default_filename\": \"index.html\"\n        }),\n    ])\n    application.listen(port=port, address=host)\n\n    log.info('Running at: http://%s:%s/', host, port)\n    log.info('Hold ctrl+c to quit.')\n    try:\n        ioloop.IOLoop.instance().start()\n    except KeyboardInterrupt:\n        log.info('Stopping server...')\n\n\ndef serve(config_file=None, dev_addr=None, strict=None, theme=None,\n          theme_dir=None, livereload='livereload'):\n    \"\"\"\n    Start the MkDocs development server\n\n    By default it will serve the documentation on http://localhost:8000/ and\n    it will rebuild the documentation and refresh the page automatically\n    whenever a file is edited.\n    \"\"\"\n\n    # Create a temporary build directory, and set some options to serve it\n    tempdir = tempfile.mkdtemp()\n\n    def builder():\n        log.info(\"Building documentation...\")\n        config = load_config(\n            config_file=config_file,\n            dev_addr=dev_addr,\n            strict=strict,\n            theme=theme,\n            theme_dir=theme_dir\n        )\n        # Override a few config settings after validation\n        config['site_dir'] = tempdir\n        config['site_url'] = 'http://{0}/'.format(config['dev_addr'])\n\n        live_server = livereload in ['dirty', 'livereload']\n        dirty = livereload == 'dirty'\n        build(config, live_server=live_server, dirty=dirty)\n        return config\n\n    try:\n        # Perform the initial build\n        config = builder()\n\n        host, port = config['dev_addr']\n\n        if livereload in ['livereload', 'dirty']:\n            _livereload(host, port, config, builder, tempdir)\n        else:\n            _static_server(host, port, tempdir)\n    finally:\n        shutil.rmtree(tempdir)\n", "path": "mkdocs/commands/serve.py"}]}