Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Put the JS embed back into script_files #92

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion readthedocs_ext/_templates/readthedocs-insert.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ READTHEDOCS_DATA = JSON.parse(document.getElementById('READTHEDOCS_DATA').innerH
</script>

<script type="text/javascript" src="{{ rtd_analytics_url }}" async="async"></script>
<script type="text/javascript" src="{{ rtd_js_url }}" async="async"></script>

<!-- end RTD <extrahead> -->
18 changes: 17 additions & 1 deletion readthedocs_ext/readthedocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ def update_body(app, pagename, templatename, context, doctree):
else:
app.add_css_file(theme_css)

# Add the Read the Docs embed
# This *must* come after Sphinx has loaded jQuery as it relies on it.
# Unless this script is modified to not rely on jQuery (a good goal),
# it can't just be put into the extrahead
# in case a theme outputs scripts at the end of the body
js_file = '{}javascript/readthedocs-doc-embed.js'.format(STATIC_URL)
if all((
app.builder.name in ONLINE_BUILDERS,
hasattr(app.builder, 'script_files'),
js_file not in app.builder.script_files,
)):
if sphinx.version_info < (1, 8):
app.builder.script_files.append(js_file)
else:
kwargs = {'async': 'async'} # Workaround reserved word in Py3.7
app.add_js_file(js_file, **kwargs)

# This is monkey patched on the signal because we can't know what the user
# has done with their `app.builder.templates` before now.

Expand Down Expand Up @@ -157,7 +174,6 @@ def rtd_render(self, template, render_context):
if ctx.get('proxied_api_host'):
ctx['rtd_data']['proxied_api_host'] = ctx['proxied_api_host']
ctx['rtd_css_url'] = '{}css/readthedocs-doc-embed.css'.format(STATIC_URL)
ctx['rtd_js_url'] = '{}javascript/readthedocs-doc-embed.js'.format(STATIC_URL)
ctx['rtd_analytics_url'] = '{}javascript/readthedocs-analytics.js'.format(STATIC_URL)
source = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
Expand Down