mirror of
https://github.com/readthedocs/sphinx_rtd_theme.git
synced 2025-02-25 18:55:21 -06:00
Debug: trigger Read the Docs Addons event to test/debug locally
Closes #1605
This commit is contained in:
parent
7b63004607
commit
250a6a8fee
38
docs/_static/debug.js
vendored
38
docs/_static/debug.js
vendored
@ -4,4 +4,40 @@ $(function () {
|
||||
$("[data-toggle='rst-debug-badge']").on("click", function () {
|
||||
$("[data-toggle='rst-versions']").toggleClass("rst-badge");
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
const EVENT_READTHEDOCS_ADDONS_DATA_READY = "readthedocs-addons-data-ready";
|
||||
|
||||
fetch("_static/addons.mocked.json", { method: "GET" })
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error("Error downloading Read the Docs Addons mocked data");
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
return dispatchEvent(
|
||||
EVENT_READTHEDOCS_ADDONS_DATA_READY,
|
||||
new ReadTheDocsEventData(data),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
// ``ReadTheDocsEventData`` and ``dispatchEvent``
|
||||
// are borrowed and adapted from Read the Docs Addons.
|
||||
// https://github.com/readthedocs/addons
|
||||
class ReadTheDocsEventData {
|
||||
constructor(data) {
|
||||
this._data = data;
|
||||
}
|
||||
|
||||
data() {
|
||||
return this._data;
|
||||
}
|
||||
}
|
||||
|
||||
function dispatchEvent(eventName, data) {
|
||||
const event = new CustomEvent(eventName, { detail: data });
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
55
docs/_templates/layout.html
vendored
55
docs/_templates/layout.html
vendored
@ -1,55 +0,0 @@
|
||||
{%- extends "!layout.html" %}
|
||||
|
||||
{#-
|
||||
|
||||
This template exists as a way to implement a version menu without changing what
|
||||
the theme normally renders the menu on local builds and on builds on Read the
|
||||
Docs. This is for local testing purposes only.
|
||||
|
||||
#}
|
||||
|
||||
{%- block footer %}
|
||||
{%- if not READTHEDOCS %}
|
||||
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="{{ _('Versions') }}">
|
||||
<span class="rst-current-version" data-toggle="rst-current-version">
|
||||
<span class="fa fa-book"> Read the Docs</span>
|
||||
v: latest
|
||||
<span class="fa fa-caret-down"></span>
|
||||
</span>
|
||||
<div class="rst-other-versions">
|
||||
<dl>
|
||||
<dt>{{ _('Versions') }}</dt>
|
||||
{%- if test_versions %}
|
||||
{%- for version in test_versions %}
|
||||
<dd><a href="#">{{ version }}</a></dd>
|
||||
{%- endfor %}
|
||||
{%- else %}
|
||||
<dd><a href="#">latest</a></dd>
|
||||
<dd><a href="#">1.0</a></dd>
|
||||
<dd><a href="#">1.1</a></dd>
|
||||
{%- endif %}
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>{{ _('Downloads') }}</dt>
|
||||
<dd><a href="#">PDF</a></dd>
|
||||
<dd><a href="#">ePub</a></dd>
|
||||
<dd><a href="#">HTML</a></dd>
|
||||
</dl>
|
||||
<dl>
|
||||
{#- Translators: The phrase "Read the Docs" is not translated #}
|
||||
<dt>{{ _('On Read the Docs') }}</dt>
|
||||
<dd>
|
||||
<a href="#">{{ _('Project Home') }}</a>
|
||||
</dd>
|
||||
<dd>
|
||||
<a href="#">{{ _('Builds') }}</a>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>Debug</dt>
|
||||
<dd><a href="#" data-toggle="rst-debug-badge">Swap badge position</a></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
{%- endif %}
|
||||
{%- endblock %}
|
@ -61,12 +61,7 @@ html_context = {}
|
||||
if not 'READTHEDOCS' in os.environ:
|
||||
html_static_path = ['_static/']
|
||||
html_js_files = ['debug.js']
|
||||
|
||||
# Add fake versions for local QA of the menu
|
||||
html_context['test_versions'] = list(map(
|
||||
lambda x: str(x / 10),
|
||||
range(1, 100)
|
||||
))
|
||||
html_context["DEBUG"] = True
|
||||
|
||||
html_logo = "demo/static/logo-wordmark-light.svg"
|
||||
html_show_sourcelink = True
|
||||
|
@ -67,7 +67,7 @@
|
||||
{%- endfor %}
|
||||
<script src="{{ pathto('_static/js/theme.js', 1) }}"></script>
|
||||
|
||||
{%- if READTHEDOCS %}
|
||||
{%- if READTHEDOCS or DEBUG %}
|
||||
<script src="{{ pathto('_static/js/versions.js', 1) }}"></script>
|
||||
{%- endif %}
|
||||
|
||||
@ -124,7 +124,7 @@
|
||||
{%- endif %}
|
||||
</a>
|
||||
|
||||
{%- if READTHEDOCS %}
|
||||
{%- if READTHEDOCS or DEBUG %}
|
||||
{%- if theme_version_selector or theme_language_selector %}
|
||||
<div class="switch-menus">
|
||||
<div class="version-switch"></div>
|
||||
|
Loading…
Reference in New Issue
Block a user