Skip to content

Commit

Permalink
refactor: html theme: Insert documentation_options.js via script_files
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Jan 23, 2021
1 parent 5ce72f4 commit a957d6f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Incompatible changes
:confval:`man_make_section_directory`)
* #8380: html search: search results are wrapped with ``<p>`` instead of
``<div>``
* html theme: Move a script tag for documentation_options.js in
basic/layout.html to ``script_files`` variable
* html theme: Move CSS tags in basic/layout.html to ``css_files`` variable
* #8508: LaTeX: uplatex becomes a default setting of latex_engine for Japanese
documents
Expand Down
4 changes: 4 additions & 0 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ def add_css_file(self, filename: str, **kwargs: Any) -> None:
self.css_files.append(Stylesheet(filename, **kwargs)) # type: ignore

def init_js_files(self) -> None:
self.add_js_file('documentation_options.js', id="documentation_options",
data_url_root='', priority=200)
self.add_js_file('jquery.js', priority=200)
self.add_js_file('underscore.js', priority=200)
self.add_js_file('doctools.js', priority=200)
Expand Down Expand Up @@ -1139,6 +1141,8 @@ def js_tag(js: JavaScript) -> str:
if value is not None:
if key == 'body':
body = value
elif key == 'data_url_root':
attrs.append('data-url_root="%s"' % pathto('', resource=True))
else:
attrs.append('%s="%s"' % (key, html.escape(value, True)))
if js.filename:
Expand Down
3 changes: 0 additions & 3 deletions sphinx/themes/basic/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
{%- set reldelim2 = reldelim2 is not defined and ' |' or reldelim2 %}
{%- set render_sidebar = (not embedded) and (not theme_nosidebar|tobool) and
(sidebars != []) %}
{%- set url_root = pathto('', 1) %}
{# URL root should never be #, then all links are fragments #}
{%- if url_root == '#' %}{% set url_root = '' %}{% endif %}
{%- if not embedded and docstitle %}
{%- set titlesuffix = " &#8212; "|safe + docstitle|e %}
{%- else %}
Expand Down Expand Up @@ -88,7 +86,6 @@ <h3>{{ _('Navigation') }}</h3>
{%- endmacro %}

{%- macro script() %}
<script id="documentation_options" data-url_root="{{ url_root }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>
{%- for js in script_files %}
{{ js_tag(js) }}
{%- endfor %}
Expand Down

0 comments on commit a957d6f

Please # to comment.