|
4 | 4 | .. _MkDocs: http://www.mkdocs.org/
|
5 | 5 | """
|
6 | 6 |
|
7 |
| -import structlog |
8 | 7 | import os
|
9 | 8 |
|
| 9 | +import structlog |
10 | 10 | import yaml
|
11 | 11 | from django.conf import settings
|
12 | 12 | from django.template import loader as template_loader
|
@@ -149,35 +149,35 @@ def append_conf(self):
|
149 | 149 |
|
150 | 150 | # Set mkdocs config values
|
151 | 151 | static_url = get_absolute_static_url()
|
| 152 | + extra_assets = { |
| 153 | + 'extra_javascript': [ |
| 154 | + 'readthedocs-data.js', |
| 155 | + f'{static_url}core/js/readthedocs-doc-embed.js', |
| 156 | + f'{static_url}javascript/readthedocs-analytics.js', |
| 157 | + ], |
| 158 | + 'extra_css': [ |
| 159 | + f'{static_url}css/badge_only.css', |
| 160 | + f'{static_url}css/readthedocs-doc-embed.css', |
| 161 | + ], |
| 162 | + } |
152 | 163 |
|
153 |
| - for config in ('extra_css', 'extra_javascript'): |
154 |
| - user_value = user_config.get(config, []) |
155 |
| - if not isinstance(user_value, list): |
| 164 | + for config, extras in extra_assets.items(): |
| 165 | + value = user_config.get(config, []) |
| 166 | + if value is None: |
| 167 | + value = [] |
| 168 | + if not isinstance(value, list): |
156 | 169 | raise MkDocsYAMLParseError(
|
157 | 170 | MkDocsYAMLParseError.INVALID_EXTRA_CONFIG.format(
|
158 | 171 | config=config,
|
159 | 172 | ),
|
160 | 173 | )
|
161 |
| - |
162 |
| - extra_javascript_list = [ |
163 |
| - 'readthedocs-data.js', |
164 |
| - '%score/js/readthedocs-doc-embed.js' % static_url, |
165 |
| - '%sjavascript/readthedocs-analytics.js' % static_url, |
166 |
| - ] |
167 |
| - extra_css_list = [ |
168 |
| - '%scss/badge_only.css' % static_url, |
169 |
| - '%scss/readthedocs-doc-embed.css' % static_url, |
170 |
| - ] |
171 |
| - |
172 |
| - # Only add static file if the files are not already in the list |
173 |
| - user_config.setdefault('extra_javascript', []).extend( |
174 |
| - [js for js in extra_javascript_list if js not in user_config.get( |
175 |
| - 'extra_javascript')] |
176 |
| - ) |
177 |
| - user_config.setdefault('extra_css', []).extend( |
178 |
| - [css for css in extra_css_list if css not in user_config.get( |
179 |
| - 'extra_css')] |
180 |
| - ) |
| 174 | + # Add the static file only if isn't already in the list. |
| 175 | + value.extend([ |
| 176 | + extra |
| 177 | + for extra in extras |
| 178 | + if extra not in value |
| 179 | + ]) |
| 180 | + user_config[config] = value |
181 | 181 |
|
182 | 182 | # The docs path is relative to the location
|
183 | 183 | # of the mkdocs configuration file.
|
|
0 commit comments