We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
MkDocs's media url shouldn't be hardcode with media_url = 'http://localhost:8000' + media_url
In file `readthedocs.org/readthedocs/doc_builder/backends/mkdocs.py`:

``` python
55        # Set mkdocs config values
56
57        media_url = getattr(settings, 'MEDIA_URL', 'https://media.readthedocs.org')
58
59        # Mkdocs needs a full domain here because it tries to link to local media files
60        if not media_url.startswith('http'):
61            media_url = 'http://localhost:8000' + media_url
```

Can u please to replace it with `SITE_URL` as the follows:

``` python
59        # Mkdocs needs a full domain here because it tries to link to local media files
60        if not media_url.startswith('http'):
61            media_url = getattr(settings, 'SITE_URL', None) + media_url
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `readthedocs/doc_builder/backends/mkdocs.py`
Content:
```
1 import os
2 import logging
3 import json
4 import yaml
5 
6 from django.conf import settings
7 from django.template import Context, loader as template_loader
8 
9 from readthedocs.doc_builder.base import BaseBuilder
10 
11 log = logging.getLogger(__name__)
12 
13 TEMPLATE_DIR = '%s/readthedocs/templates/mkdocs/readthedocs' % settings.SITE_ROOT
14 OVERRIDE_TEMPLATE_DIR = '%s/readthedocs/templates/mkdocs/overrides' % settings.SITE_ROOT
15 
16 
17 class BaseMkdocs(BaseBuilder):
18 
19     """
20     Mkdocs builder
21     """
22     use_theme = True
23 
24     def __init__(self, *args, **kwargs):
25         super(BaseMkdocs, self).__init__(*args, **kwargs)
26         self.old_artifact_path = os.path.join(
27             self.version.project.checkout_path(self.version.slug),
28             self.build_dir)
29         self.root_path = self.version.project.checkout_path(self.version.slug)
30 
31     def append_conf(self, **kwargs):
32         """
33         Set mkdocs config values
34         """
35 
36         # Pull mkdocs config data
37         try:
38             user_config = yaml.safe_load(
39                 open(os.path.join(self.root_path, 'mkdocs.yml'), 'r')
40             )
41         except IOError:
42             user_config = {
43                 'site_name': self.version.project.name,
44             }
45 
46         # Handle custom docs dirs
47 
48         user_docs_dir = user_config.get('docs_dir')
49         if user_docs_dir:
50             user_docs_dir = os.path.join(self.root_path, user_docs_dir)
51         docs_dir = self.docs_dir(docs_dir=user_docs_dir)
52         self.create_index(extension='md')
53         user_config['docs_dir'] = docs_dir
54 
55         # Set mkdocs config values
56 
57         media_url = getattr(settings, 'MEDIA_URL', 'https://media.readthedocs.org')
58 
59         # Mkdocs needs a full domain here because it tries to link to local media files
60         if not media_url.startswith('http'):
61             media_url = 'http://localhost:8000' + media_url
62 
63         if 'extra_javascript' in user_config:
64             user_config['extra_javascript'].append('readthedocs-data.js')
65             user_config['extra_javascript'].append(
66                 'readthedocs-dynamic-include.js')
67             user_config['extra_javascript'].append(
68                 '%sjavascript/readthedocs-doc-embed.js' % media_url)
69         else:
70             user_config['extra_javascript'] = [
71                 'readthedocs-data.js',
72                 'readthedocs-dynamic-include.js',
73                 '%sjavascript/readthedocs-doc-embed.js' % media_url,
74             ]
75 
76         if 'extra_css' in user_config:
77             user_config['extra_css'].append(
78                 '%s/css/badge_only.css' % media_url)
79             user_config['extra_css'].append(
80                 '%s/css/readthedocs-doc-embed.css' % media_url)
81         else:
82             user_config['extra_css'] = [
83                 '%scss/badge_only.css' % media_url,
84                 '%scss/readthedocs-doc-embed.css' % media_url,
85             ]
86 
87         # Set our custom theme dir for mkdocs
88         if 'theme_dir' not in user_config and self.use_theme:
89             user_config['theme_dir'] = TEMPLATE_DIR
90 
91         yaml.dump(
92             user_config,
93             open(os.path.join(self.root_path, 'mkdocs.yml'), 'w')
94         )
95 
96         # RTD javascript writing
97 
98         # Will be available in the JavaScript as READTHEDOCS_DATA.
99         readthedocs_data = {
100             'project': self.version.project.slug,
101             'version': self.version.slug,
102             'language': self.version.project.language,
103             'page': None,
104             'theme': "readthedocs",
105             'builder': "mkdocs",
106             'docroot': docs_dir,
107             'source_suffix': ".md",
108             'api_host': getattr(settings, 'PUBLIC_API_URL',
109                                 'https://readthedocs.org'),
110             'commit': self.version.project.vcs_repo(self.version.slug).commit,
111         }
112         data_json = json.dumps(readthedocs_data, indent=4)
113         data_ctx = {
114             'data_json': data_json,
115             'current_version': readthedocs_data['version'],
116             'slug': readthedocs_data['project'],
117             'html_theme': readthedocs_data['theme'],
118             'pagename': None,
119         }
120         data_string = template_loader.get_template(
121             'doc_builder/data.js.tmpl'
122         ).render(data_ctx)
123 
124         data_file = open(os.path.join(self.root_path, docs_dir, 'readthedocs-data.js'), 'w+')
125         data_file.write(data_string)
126         data_file.write('''
127 READTHEDOCS_DATA["page"] = mkdocs_page_input_path.substr(
128     0, mkdocs_page_input_path.lastIndexOf(READTHEDOCS_DATA.source_suffix));
129 ''')
130         data_file.close()
131 
132         include_ctx = {
133             'global_analytics_code': getattr(settings, 'GLOBAL_ANALYTICS_CODE', 'UA-17997319-1'),
134             'user_analytics_code': self.version.project.analytics_code,
135         }
136         include_string = template_loader.get_template(
137             'doc_builder/include.js.tmpl'
138         ).render(include_ctx)
139         include_file = open(
140             os.path.join(self.root_path, docs_dir, 'readthedocs-dynamic-include.js'),
141             'w+'
142         )
143         include_file.write(include_string)
144         include_file.close()
145 
146     def build(self, **kwargs):
147         checkout_path = self.project.checkout_path(self.version.slug)
148         build_command = [
149             'python',
150             self.python_env.venv_bin(filename='mkdocs'),
151             self.builder,
152             '--clean',
153             '--site-dir', self.build_dir,
154         ]
155         if self.use_theme:
156             build_command.extend(['--theme', 'readthedocs'])
157         cmd_ret = self.run(
158             *build_command,
159             cwd=checkout_path,
160             bin_path=self.python_env.venv_bin()
161         )
162         return cmd_ret.successful
163 
164 
165 class MkdocsHTML(BaseMkdocs):
166     type = 'mkdocs'
167     builder = 'build'
168     build_dir = '_build/html'
169 
170 
171 class MkdocsJSON(BaseMkdocs):
172     type = 'mkdocs_json'
173     builder = 'json'
174     build_dir = '_build/json'
175     use_theme = False
176 
177     def build(self, **kwargs):
178         user_config = yaml.safe_load(
179             open(os.path.join(self.root_path, 'mkdocs.yml'), 'r')
180         )
181         if user_config['theme_dir'] == TEMPLATE_DIR:
182             del user_config['theme_dir']
183         yaml.dump(
184             user_config,
185             open(os.path.join(self.root_path, 'mkdocs.yml'), 'w')
186         )
187         super(MkdocsJSON, self).build(**kwargs)
188
```
--- 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/readthedocs/doc_builder/backends/mkdocs.py b/readthedocs/doc_builder/backends/mkdocs.py
--- a/readthedocs/doc_builder/backends/mkdocs.py
+++ b/readthedocs/doc_builder/backends/mkdocs.py
@@ -58,7 +58,8 @@
 
         # Mkdocs needs a full domain here because it tries to link to local media files
         if not media_url.startswith('http'):
-            media_url = 'http://localhost:8000' + media_url
+            domain = getattr(settings, 'PRODUCTION_DOMAIN')
+            media_url = 'http://{}/{}'.format(domain, media_url)
 
         if 'extra_javascript' in user_config:
             user_config['extra_javascript'].append('readthedocs-data.js')

{"golden_diff": "diff --git a/readthedocs/doc_builder/backends/mkdocs.py b/readthedocs/doc_builder/backends/mkdocs.py\n--- a/readthedocs/doc_builder/backends/mkdocs.py\n+++ b/readthedocs/doc_builder/backends/mkdocs.py\n@@ -58,7 +58,8 @@\n \n         # Mkdocs needs a full domain here because it tries to link to local media files\n         if not media_url.startswith('http'):\n-            media_url = 'http://localhost:8000' + media_url\n+            domain = getattr(settings, 'PRODUCTION_DOMAIN')\n+            media_url = 'http://{}/{}'.format(domain, media_url)\n \n         if 'extra_javascript' in user_config:\n             user_config['extra_javascript'].append('readthedocs-data.js')\n", "issue": "MkDocs's media url shouldn't be hardcode with media_url = 'http://localhost:8000' + media_url\nIn file `readthedocs.org/readthedocs/doc_builder/backends/mkdocs.py`:\n\n``` python\n55        # Set mkdocs config values\n56\n57        media_url = getattr(settings, 'MEDIA_URL', 'https://media.readthedocs.org')\n58\n59        # Mkdocs needs a full domain here because it tries to link to local media files\n60        if not media_url.startswith('http'):\n61            media_url = 'http://localhost:8000' + media_url\n```\n\nCan u please to replace it with `SITE_URL` as the follows:\n\n``` python\n59        # Mkdocs needs a full domain here because it tries to link to local media files\n60        if not media_url.startswith('http'):\n61            media_url = getattr(settings, 'SITE_URL', None) + media_url\n```\n\n", "before_files": [{"content": "import os\nimport logging\nimport json\nimport yaml\n\nfrom django.conf import settings\nfrom django.template import Context, loader as template_loader\n\nfrom readthedocs.doc_builder.base import BaseBuilder\n\nlog = logging.getLogger(__name__)\n\nTEMPLATE_DIR = '%s/readthedocs/templates/mkdocs/readthedocs' % settings.SITE_ROOT\nOVERRIDE_TEMPLATE_DIR = '%s/readthedocs/templates/mkdocs/overrides' % settings.SITE_ROOT\n\n\nclass BaseMkdocs(BaseBuilder):\n\n    \"\"\"\n    Mkdocs builder\n    \"\"\"\n    use_theme = True\n\n    def __init__(self, *args, **kwargs):\n        super(BaseMkdocs, self).__init__(*args, **kwargs)\n        self.old_artifact_path = os.path.join(\n            self.version.project.checkout_path(self.version.slug),\n            self.build_dir)\n        self.root_path = self.version.project.checkout_path(self.version.slug)\n\n    def append_conf(self, **kwargs):\n        \"\"\"\n        Set mkdocs config values\n        \"\"\"\n\n        # Pull mkdocs config data\n        try:\n            user_config = yaml.safe_load(\n                open(os.path.join(self.root_path, 'mkdocs.yml'), 'r')\n            )\n        except IOError:\n            user_config = {\n                'site_name': self.version.project.name,\n            }\n\n        # Handle custom docs dirs\n\n        user_docs_dir = user_config.get('docs_dir')\n        if user_docs_dir:\n            user_docs_dir = os.path.join(self.root_path, user_docs_dir)\n        docs_dir = self.docs_dir(docs_dir=user_docs_dir)\n        self.create_index(extension='md')\n        user_config['docs_dir'] = docs_dir\n\n        # Set mkdocs config values\n\n        media_url = getattr(settings, 'MEDIA_URL', 'https://media.readthedocs.org')\n\n        # Mkdocs needs a full domain here because it tries to link to local media files\n        if not media_url.startswith('http'):\n            media_url = 'http://localhost:8000' + media_url\n\n        if 'extra_javascript' in user_config:\n            user_config['extra_javascript'].append('readthedocs-data.js')\n            user_config['extra_javascript'].append(\n                'readthedocs-dynamic-include.js')\n            user_config['extra_javascript'].append(\n                '%sjavascript/readthedocs-doc-embed.js' % media_url)\n        else:\n            user_config['extra_javascript'] = [\n                'readthedocs-data.js',\n                'readthedocs-dynamic-include.js',\n                '%sjavascript/readthedocs-doc-embed.js' % media_url,\n            ]\n\n        if 'extra_css' in user_config:\n            user_config['extra_css'].append(\n                '%s/css/badge_only.css' % media_url)\n            user_config['extra_css'].append(\n                '%s/css/readthedocs-doc-embed.css' % media_url)\n        else:\n            user_config['extra_css'] = [\n                '%scss/badge_only.css' % media_url,\n                '%scss/readthedocs-doc-embed.css' % media_url,\n            ]\n\n        # Set our custom theme dir for mkdocs\n        if 'theme_dir' not in user_config and self.use_theme:\n            user_config['theme_dir'] = TEMPLATE_DIR\n\n        yaml.dump(\n            user_config,\n            open(os.path.join(self.root_path, 'mkdocs.yml'), 'w')\n        )\n\n        # RTD javascript writing\n\n        # Will be available in the JavaScript as READTHEDOCS_DATA.\n        readthedocs_data = {\n            'project': self.version.project.slug,\n            'version': self.version.slug,\n            'language': self.version.project.language,\n            'page': None,\n            'theme': \"readthedocs\",\n            'builder': \"mkdocs\",\n            'docroot': docs_dir,\n            'source_suffix': \".md\",\n            'api_host': getattr(settings, 'PUBLIC_API_URL',\n                                'https://readthedocs.org'),\n            'commit': self.version.project.vcs_repo(self.version.slug).commit,\n        }\n        data_json = json.dumps(readthedocs_data, indent=4)\n        data_ctx = {\n            'data_json': data_json,\n            'current_version': readthedocs_data['version'],\n            'slug': readthedocs_data['project'],\n            'html_theme': readthedocs_data['theme'],\n            'pagename': None,\n        }\n        data_string = template_loader.get_template(\n            'doc_builder/data.js.tmpl'\n        ).render(data_ctx)\n\n        data_file = open(os.path.join(self.root_path, docs_dir, 'readthedocs-data.js'), 'w+')\n        data_file.write(data_string)\n        data_file.write('''\nREADTHEDOCS_DATA[\"page\"] = mkdocs_page_input_path.substr(\n    0, mkdocs_page_input_path.lastIndexOf(READTHEDOCS_DATA.source_suffix));\n''')\n        data_file.close()\n\n        include_ctx = {\n            'global_analytics_code': getattr(settings, 'GLOBAL_ANALYTICS_CODE', 'UA-17997319-1'),\n            'user_analytics_code': self.version.project.analytics_code,\n        }\n        include_string = template_loader.get_template(\n            'doc_builder/include.js.tmpl'\n        ).render(include_ctx)\n        include_file = open(\n            os.path.join(self.root_path, docs_dir, 'readthedocs-dynamic-include.js'),\n            'w+'\n        )\n        include_file.write(include_string)\n        include_file.close()\n\n    def build(self, **kwargs):\n        checkout_path = self.project.checkout_path(self.version.slug)\n        build_command = [\n            'python',\n            self.python_env.venv_bin(filename='mkdocs'),\n            self.builder,\n            '--clean',\n            '--site-dir', self.build_dir,\n        ]\n        if self.use_theme:\n            build_command.extend(['--theme', 'readthedocs'])\n        cmd_ret = self.run(\n            *build_command,\n            cwd=checkout_path,\n            bin_path=self.python_env.venv_bin()\n        )\n        return cmd_ret.successful\n\n\nclass MkdocsHTML(BaseMkdocs):\n    type = 'mkdocs'\n    builder = 'build'\n    build_dir = '_build/html'\n\n\nclass MkdocsJSON(BaseMkdocs):\n    type = 'mkdocs_json'\n    builder = 'json'\n    build_dir = '_build/json'\n    use_theme = False\n\n    def build(self, **kwargs):\n        user_config = yaml.safe_load(\n            open(os.path.join(self.root_path, 'mkdocs.yml'), 'r')\n        )\n        if user_config['theme_dir'] == TEMPLATE_DIR:\n            del user_config['theme_dir']\n        yaml.dump(\n            user_config,\n            open(os.path.join(self.root_path, 'mkdocs.yml'), 'w')\n        )\n        super(MkdocsJSON, self).build(**kwargs)\n", "path": "readthedocs/doc_builder/backends/mkdocs.py"}], "after_files": [{"content": "import os\nimport logging\nimport json\nimport yaml\n\nfrom django.conf import settings\nfrom django.template import Context, loader as template_loader\n\nfrom readthedocs.doc_builder.base import BaseBuilder\n\nlog = logging.getLogger(__name__)\n\nTEMPLATE_DIR = '%s/readthedocs/templates/mkdocs/readthedocs' % settings.SITE_ROOT\nOVERRIDE_TEMPLATE_DIR = '%s/readthedocs/templates/mkdocs/overrides' % settings.SITE_ROOT\n\n\nclass BaseMkdocs(BaseBuilder):\n\n    \"\"\"\n    Mkdocs builder\n    \"\"\"\n    use_theme = True\n\n    def __init__(self, *args, **kwargs):\n        super(BaseMkdocs, self).__init__(*args, **kwargs)\n        self.old_artifact_path = os.path.join(\n            self.version.project.checkout_path(self.version.slug),\n            self.build_dir)\n        self.root_path = self.version.project.checkout_path(self.version.slug)\n\n    def append_conf(self, **kwargs):\n        \"\"\"\n        Set mkdocs config values\n        \"\"\"\n\n        # Pull mkdocs config data\n        try:\n            user_config = yaml.safe_load(\n                open(os.path.join(self.root_path, 'mkdocs.yml'), 'r')\n            )\n        except IOError:\n            user_config = {\n                'site_name': self.version.project.name,\n            }\n\n        # Handle custom docs dirs\n\n        user_docs_dir = user_config.get('docs_dir')\n        if user_docs_dir:\n            user_docs_dir = os.path.join(self.root_path, user_docs_dir)\n        docs_dir = self.docs_dir(docs_dir=user_docs_dir)\n        self.create_index(extension='md')\n        user_config['docs_dir'] = docs_dir\n\n        # Set mkdocs config values\n\n        media_url = getattr(settings, 'MEDIA_URL', 'https://media.readthedocs.org')\n\n        # Mkdocs needs a full domain here because it tries to link to local media files\n        if not media_url.startswith('http'):\n            domain = getattr(settings, 'PRODUCTION_DOMAIN')\n            media_url = 'http://{}/{}'.format(domain, media_url)\n\n        if 'extra_javascript' in user_config:\n            user_config['extra_javascript'].append('readthedocs-data.js')\n            user_config['extra_javascript'].append(\n                'readthedocs-dynamic-include.js')\n            user_config['extra_javascript'].append(\n                '%sjavascript/readthedocs-doc-embed.js' % media_url)\n        else:\n            user_config['extra_javascript'] = [\n                'readthedocs-data.js',\n                'readthedocs-dynamic-include.js',\n                '%sjavascript/readthedocs-doc-embed.js' % media_url,\n            ]\n\n        if 'extra_css' in user_config:\n            user_config['extra_css'].append(\n                '%s/css/badge_only.css' % media_url)\n            user_config['extra_css'].append(\n                '%s/css/readthedocs-doc-embed.css' % media_url)\n        else:\n            user_config['extra_css'] = [\n                '%scss/badge_only.css' % media_url,\n                '%scss/readthedocs-doc-embed.css' % media_url,\n            ]\n\n        # Set our custom theme dir for mkdocs\n        if 'theme_dir' not in user_config and self.use_theme:\n            user_config['theme_dir'] = TEMPLATE_DIR\n\n        yaml.dump(\n            user_config,\n            open(os.path.join(self.root_path, 'mkdocs.yml'), 'w')\n        )\n\n        # RTD javascript writing\n\n        # Will be available in the JavaScript as READTHEDOCS_DATA.\n        readthedocs_data = {\n            'project': self.version.project.slug,\n            'version': self.version.slug,\n            'language': self.version.project.language,\n            'page': None,\n            'theme': \"readthedocs\",\n            'builder': \"mkdocs\",\n            'docroot': docs_dir,\n            'source_suffix': \".md\",\n            'api_host': getattr(settings, 'PUBLIC_API_URL',\n                                'https://readthedocs.org'),\n            'commit': self.version.project.vcs_repo(self.version.slug).commit,\n        }\n        data_json = json.dumps(readthedocs_data, indent=4)\n        data_ctx = {\n            'data_json': data_json,\n            'current_version': readthedocs_data['version'],\n            'slug': readthedocs_data['project'],\n            'html_theme': readthedocs_data['theme'],\n            'pagename': None,\n        }\n        data_string = template_loader.get_template(\n            'doc_builder/data.js.tmpl'\n        ).render(data_ctx)\n\n        data_file = open(os.path.join(self.root_path, docs_dir, 'readthedocs-data.js'), 'w+')\n        data_file.write(data_string)\n        data_file.write('''\nREADTHEDOCS_DATA[\"page\"] = mkdocs_page_input_path.substr(\n    0, mkdocs_page_input_path.lastIndexOf(READTHEDOCS_DATA.source_suffix));\n''')\n        data_file.close()\n\n        include_ctx = {\n            'global_analytics_code': getattr(settings, 'GLOBAL_ANALYTICS_CODE', 'UA-17997319-1'),\n            'user_analytics_code': self.version.project.analytics_code,\n        }\n        include_string = template_loader.get_template(\n            'doc_builder/include.js.tmpl'\n        ).render(include_ctx)\n        include_file = open(\n            os.path.join(self.root_path, docs_dir, 'readthedocs-dynamic-include.js'),\n            'w+'\n        )\n        include_file.write(include_string)\n        include_file.close()\n\n    def build(self, **kwargs):\n        checkout_path = self.project.checkout_path(self.version.slug)\n        build_command = [\n            'python',\n            self.python_env.venv_bin(filename='mkdocs'),\n            self.builder,\n            '--clean',\n            '--site-dir', self.build_dir,\n        ]\n        if self.use_theme:\n            build_command.extend(['--theme', 'readthedocs'])\n        cmd_ret = self.run(\n            *build_command,\n            cwd=checkout_path,\n            bin_path=self.python_env.venv_bin()\n        )\n        return cmd_ret.successful\n\n\nclass MkdocsHTML(BaseMkdocs):\n    type = 'mkdocs'\n    builder = 'build'\n    build_dir = '_build/html'\n\n\nclass MkdocsJSON(BaseMkdocs):\n    type = 'mkdocs_json'\n    builder = 'json'\n    build_dir = '_build/json'\n    use_theme = False\n\n    def build(self, **kwargs):\n        user_config = yaml.safe_load(\n            open(os.path.join(self.root_path, 'mkdocs.yml'), 'r')\n        )\n        if user_config['theme_dir'] == TEMPLATE_DIR:\n            del user_config['theme_dir']\n        yaml.dump(\n            user_config,\n            open(os.path.join(self.root_path, 'mkdocs.yml'), 'w')\n        )\n        super(MkdocsJSON, self).build(**kwargs)\n", "path": "readthedocs/doc_builder/backends/mkdocs.py"}]}