Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug: trigger Read the Docs Addons event to test/debug locally #1606

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 37 additions & 1 deletion docs/_static/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
humitos marked this conversation as resolved.
Show resolved Hide resolved
.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 changes: 0 additions & 55 deletions docs/_templates/layout.html

This file was deleted.

7 changes: 1 addition & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@
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
Expand Down
4 changes: 2 additions & 2 deletions sphinx_rtd_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down Expand Up @@ -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>
Expand Down