Skip to content

Commit adc8b1d

Browse files
authored
ENH: place the RDT flyout in the sidebar (#1005)
* try to set the flyout in the left bottom corner * add a mutation observer * add some styling * typo * start customization * customization * avoid y scroll * custom content * custom content * typo * fix test * color of the links * color to surface * final custom ? * bug in margins * custom for small screen
1 parent 6d3968a commit adc8b1d

File tree

5 files changed

+104
-1
lines changed

5 files changed

+104
-1
lines changed

src/pydata_sphinx_theme/assets/scripts/index.js

+28
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,33 @@ if (themeSwitchBtns) {
350350
);
351351
}
352352

353+
/*******************************************************************************
354+
* MutationObserver to move the ReadTheDocs button
355+
*/
356+
357+
function initRTDObserver() {
358+
const mutatedCallback = (mutationList, observer) => {
359+
mutationList.forEach((mutation) => {
360+
// Check whether the mutation is for RTD, which will have a specific structure
361+
if (mutation.addedNodes.length === 0) {
362+
return;
363+
}
364+
if (mutation.addedNodes[0].data === undefined) {
365+
return;
366+
}
367+
if (mutation.addedNodes[0].data.search("Inserted RTD Footer") != -1) {
368+
mutation.addedNodes.forEach((node) => {
369+
document.getElementById("rtd-footer-container").append(node);
370+
});
371+
}
372+
});
373+
};
374+
375+
const observer = new MutationObserver(mutatedCallback);
376+
const config = { childList: true };
377+
observer.observe(document.body, config);
378+
}
379+
353380
/*******************************************************************************
354381
* Finalize
355382
*/
@@ -361,3 +388,4 @@ $(scrollToActive);
361388
$(addTOCInteractivity);
362389
$(setupSearchButtons);
363390
$('[data-toggle="tooltip"]').tooltip({ delay: { show: 500, hide: 100 } });
391+
$(initRTDObserver);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
.bd-sidebar-primary div#rtd-footer-container {
2+
position: sticky;
3+
bottom: -1rem;
4+
margin: -1rem; // ignore sidebar padding
5+
6+
.rst-versions.rst-badge {
7+
position: unset;
8+
font-size: 0.9em;
9+
font-family: var(--pst-font-family-base);
10+
max-width: unset;
11+
12+
.rst-current-version {
13+
display: flex;
14+
align-items: center;
15+
gap: 0.2rem;
16+
height: 2.5rem;
17+
transition: background-color 0.2s ease-out;
18+
background-color: var(--pst-color-background);
19+
color: var(--pst-color-success);
20+
border-top: 1px solid var(--pst-color-border);
21+
}
22+
23+
.fa.fa-book {
24+
color: var(--pst-color-text-muted);
25+
margin-right: auto;
26+
27+
&::after {
28+
color: var(--pst-color-text-base);
29+
content: "Read The Docs";
30+
font-family: var(--pst-font-family-base);
31+
font-weight: var(--pst-font-weight-heading);
32+
}
33+
}
34+
.fa.fa-caret-down {
35+
color: var(--pst-color-text-muted);
36+
}
37+
}
38+
39+
.rst-versions.rst-badge.shift-up {
40+
.rst-current-version {
41+
border-bottom: 1px solid var(--pst-color-border);
42+
}
43+
}
44+
45+
.rst-other-versions {
46+
background-color: var(--pst-color-surface);
47+
color: var(--pst-color-text-base);
48+
49+
dl {
50+
dd a {
51+
color: var(--pst-color-text-muted);
52+
}
53+
}
54+
55+
hr {
56+
background-color: var(--pst-color-border);
57+
}
58+
59+
small a {
60+
color: var(--pst-color-link);
61+
}
62+
63+
input {
64+
padding-left: 0.5rem;
65+
border: 1px solid var(--pst-color-border);
66+
background-color: var(--pst-color-surface);
67+
}
68+
}
69+
}

src/pydata_sphinx_theme/assets/styles/index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ $grid-breakpoints: (
5555
@import "./components/toc-inpage";
5656
@import "./components/versionmodified";
5757
@import "./components/indices";
58+
@import "./components/readthedocs-switcher";
5859

5960
// Content blocks in standard Sphinx
6061
@import "./content/admonitions";

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@
3434
</div>
3535
{% endif %}
3636

37-
{# Items that will snap to the bottom of the screen#}
37+
{# Items that will snap to the bottom of the screen #}
3838
<div class="sidebar-end-items sidebar-primary__section">
3939
{%- for sidebartemplate in theme_primary_sidebar_end %}
4040
<div class="sidebar-end-items__item">
4141
{%- include sidebartemplate %}
4242
</div>
4343
{%- endfor %}
4444
</div>
45+
46+
{# add the rtd flyout in the sidebar if existing #}
47+
<div id="rtd-footer-container"></div>
4548
{% endblock %}

tests/test_build/sidebar_subpage.html

+2
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@
7979
<div class="sidebar-end-items__item">
8080
</div>
8181
</div>
82+
<div id="rtd-footer-container">
83+
</div>
8284
</div>

0 commit comments

Comments
 (0)