Skip to content

Commit 05a46f5

Browse files
tk0miyabillsacks
authored andcommitted
Fix HTML search not working with Sphinx-1.8. (readthedocs#672)
* Fix HTML search not working Since Sphinx-1.7, Sphinx has exported search options as `documentation_options.js`. This starts to refer it instead of definitions of JavaScript variables. In addition, this also uses `js_tag()` function which added in 1.8 to support additional attributes for scripts (ex. async attribute). * Add code comment
1 parent b46bba5 commit 05a46f5

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

sphinx_rtd_theme/layout.html

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,28 @@
191191

192192
{% if not embedded %}
193193

194-
<script type="text/javascript">
195-
var DOCUMENTATION_OPTIONS = {
196-
URL_ROOT:'{{ url_root }}',
197-
VERSION:'{{ release|e }}',
198-
LANGUAGE:'{{ language }}',
199-
COLLAPSE_INDEX:false,
200-
FILE_SUFFIX:'{{ '' if no_search_suffix else file_suffix }}',
201-
HAS_SOURCE: {{ has_source|lower }},
202-
SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}'
203-
};
204-
</script>
205-
{%- for scriptfile in script_files %}
206-
<script type="text/javascript" src="{{ pathto(scriptfile, 1) }}"></script>
207-
{%- endfor %}
194+
{# XXX Sphinx 1.8.0 made this an external js-file, quick fix until we refactor the template to inherert more blocks directly from sphinx #}
195+
{% if sphinx_version >= "1.8.0" %}
196+
<script type="text/javascript" id="documentation_options" data-url_root="{{ pathto('', 1) }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>
197+
{%- for scriptfile in script_files %}
198+
{{ js_tag(scriptfile) }}
199+
{%- endfor %}
200+
{% else %}
201+
<script type="text/javascript">
202+
var DOCUMENTATION_OPTIONS = {
203+
URL_ROOT:'{{ url_root }}',
204+
VERSION:'{{ release|e }}',
205+
LANGUAGE:'{{ language }}',
206+
COLLAPSE_INDEX:false,
207+
FILE_SUFFIX:'{{ '' if no_search_suffix else file_suffix }}',
208+
HAS_SOURCE: {{ has_source|lower }},
209+
SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}'
210+
};
211+
</script>
212+
{%- for scriptfile in script_files %}
213+
<script type="text/javascript" src="{{ pathto(scriptfile, 1) }}"></script>
214+
{%- endfor %}
215+
{% endif %}
208216

209217
{% endif %}
210218

0 commit comments

Comments
 (0)