Skip to content

Commit 92f5110

Browse files
authored
Stop moving the Read the Docs version switcher into the sidebar (#2034)
Read the Docs recently rolled out its new "addons" project. This broke assumptions made by code in our theme. In particular, it means that all of the code that tries to move the Read the Docs version switcher into the sidebar no longer works, so this pull request removes all of that code and updates the docs. I also removed the check for Read the Docs in the Ethical Ads template because as far as I understand, that template is opt-in anyway, meaning that sites that use our theme do not have that template included by default. Fixes #1794 and possibly #1238. This pull request does not address #1933, which is about providing a better integration with Read the Docs. The only goal of this pull request is to remove code that is broken as a result of the addons rollout.
1 parent feb0c91 commit 92f5110

File tree

7 files changed

+30
-123
lines changed

7 files changed

+30
-123
lines changed

docs/user_guide/readthedocs.md

+20-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@ This theme comes with support for {{ rtd }}, a popular service for hosting docum
44

55
## Version switcher
66

7-
Projects hosted on {{ rtd }} can use the {{ rtd }} supplied version switcher instead of the [version switcher that this theme provides](version-dropdown.rst).
8-
Its presence will be automatically detected by this theme, and placed in the `rtd-footer-container` node inside the primary sidebar.
9-
10-
```{warning}
11-
The {{ rtd }} version switcher will be hidden any time the primary sidebar is hidden (see [this section](layout-sidebar-primary) for discussion of when the primary sidebar might get hidden automatically and how to hide it purposely).
12-
We intend to make {{ rtd }} switcher placement more flexible; you can track progress toward that in [this issue](https://github.com/pydata/pydata-sphinx-theme/issues/705). This problem doesn't apply to the version switcher provided by
13-
the [flyout add-on](https://docs.readthedocs.io/en/stable/addons.html) which can be enabled through your project's settings.
14-
```
7+
Read the Docs provides a version switcher by default to projects as part of a
8+
[flyout menu](https://docs.readthedocs.io/en/stable/flyout-menu.html) that can
9+
be disabled.
10+
11+
This means that you have one of three options if you are hosting a PyData
12+
Sphinx Theme-enabled site on Read the Docs:
13+
14+
1. Use only the Read the Docs version switcher. You must disable the [version
15+
switcher that this theme provides](version-dropdown.rst) if you previously
16+
enabled it.
17+
2. Use only this theme's version switcher. You must disable the Read the Docs
18+
version switcher by going to your project's [Read the Docs
19+
dashboard](https://app.readthedocs.org/dashboard/). Then go to
20+
`Settings > Addons > Flyout menu` and uncheck the "Flyout enabled" box.
21+
3. Not recommended: use both version switchers.
22+
23+
Be aware that the two version switchers are not feature equivalent. For example,
24+
the Read the Docs flyout provides a translation switcher in addition to a
25+
version switcher. On the other hand, the Read the Docs switcher is not styled to
26+
match the look and feel of this theme. And there are other differences.
1527

1628
## Add ethical advertisements to your sidebar
1729

src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js

-32
Original file line numberDiff line numberDiff line change
@@ -609,37 +609,6 @@ function showVersionWarningBanner(data) {
609609
banner.classList.remove("d-none");
610610
}
611611

612-
/*******************************************************************************
613-
* MutationObserver to move the ReadTheDocs button
614-
*/
615-
616-
/**
617-
* intercept the RTD flyout and place it in the rtd-footer-container if existing
618-
* if not it stays where on top of the page
619-
*/
620-
function initRTDObserver() {
621-
const mutatedCallback = (mutationList, observer) => {
622-
mutationList.forEach((mutation) => {
623-
// Check whether the mutation is for RTD, which will have a specific structure
624-
if (mutation.addedNodes.length === 0) {
625-
return;
626-
}
627-
if (mutation.addedNodes[0].data === undefined) {
628-
return;
629-
}
630-
if (mutation.addedNodes[0].data.search("Inserted RTD Footer") != -1) {
631-
mutation.addedNodes.forEach((node) => {
632-
document.getElementById("rtd-footer-container").append(node);
633-
});
634-
}
635-
});
636-
};
637-
638-
const observer = new MutationObserver(mutatedCallback);
639-
const config = { childList: true };
640-
observer.observe(document.body, config);
641-
}
642-
643612
async function fetchAndUseVersions() {
644613
// fetch the JSON version data (only once), then use it to populate the version
645614
// switcher and maybe show the version warning bar
@@ -880,7 +849,6 @@ documentReady(addModeListener);
880849
documentReady(scrollToActive);
881850
documentReady(addTOCInteractivity);
882851
documentReady(setupSearchButtons);
883-
documentReady(initRTDObserver);
884852
documentReady(setupMobileSidebarKeyboardHandlers);
885853

886854
// Determining whether an element has scrollable content depends on stylesheets,

src/pydata_sphinx_theme/assets/styles/components/_readthedocs-switcher.scss

-70
This file was deleted.

src/pydata_sphinx_theme/assets/styles/pydata-sphinx-theme.scss

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
@import "./components/toc-inpage";
5151
@import "./components/versionmodified";
5252
@import "./components/indices";
53-
@import "./components/readthedocs-switcher";
5453

5554
// Content blocks in standard Sphinx
5655
@import "./content/admonitions";
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{# For sites hosted on ReadTheDocs, displays "ethical ads". #}
2-
{% if READTHEDOCS %}
3-
<div id="ethical-ad-placement"
4-
class="flat"
5-
data-ea-publisher="readthedocs"
6-
data-ea-type="readthedocs-sidebar"
7-
data-ea-manual="true">
8-
</div>
9-
{% endif %}
2+
<div id="ethical-ad-placement"
3+
class="flat"
4+
data-ea-publisher="readthedocs"
5+
data-ea-type="readthedocs-sidebar"
6+
data-ea-manual="true">
7+
</div>

src/pydata_sphinx_theme/theme/pydata_sphinx_theme/sections/sidebar-primary.html

-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,5 @@
3737
<div class="sidebar-primary-item">{%- include sidebartemplate %}</div>
3838
{%- endfor %}
3939
</div>
40-
{# add the rtd flyout in the sidebar if existing #}
41-
<div id="rtd-footer-container"></div>
4240
{% endif %}
4341
{% endblock docs_sidebar %}

tests/test_build/sidebar_subpage.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
</div>
6969
</div>
7070
<div class="sidebar-primary-items__end sidebar-primary__section">
71-
</div>
72-
<div id="rtd-footer-container">
71+
<div class="sidebar-primary-item">
72+
<div class="flat" data-ea-manual="true" data-ea-publisher="readthedocs" data-ea-type="readthedocs-sidebar" id="ethical-ad-placement">
73+
</div>
74+
</div>
7375
</div>
7476
</div>

0 commit comments

Comments
 (0)