Skip to content

Commit 37c8850

Browse files
authored
feat: switch to readthedocs search addon (#122)
* feat: switch to readthedocs search addon The extension is no longer supported. * chore: remove unused search extension * chore: remove css for old search extension
1 parent 898b5ab commit 37c8850

File tree

4 files changed

+42
-100
lines changed

4 files changed

+42
-100
lines changed

_static/css/pydata-overrides.css

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -121,84 +121,3 @@ sphinx search extension interface.
121121
.search-button__wrapper.show .search-button__search-container {
122122
width: 15%;
123123
}
124-
125-
/* Handle actual styling of the RtD search extension's screen */
126-
.search__outer {
127-
background-color: var(--pst-color-on-background);
128-
border: var(--pst-color-border);
129-
border-radius: 0.25em;
130-
}
131-
132-
.search__outer__input {
133-
background-color: var(--pst-color-on-background);
134-
color: var(--pst-color-text-base);
135-
font-size: var(--pst-font-size-icon);
136-
}
137-
138-
.search__result__title {
139-
color: var(--pst-color-primary);
140-
border-bottom-color: var(--pst-color-primary)
141-
}
142-
143-
.search__result__content,
144-
.search__result__subheading,
145-
.search__error__box {
146-
color: var(--pst-color-text-base);
147-
}
148-
149-
.search__result__subheading span {
150-
border-bottom-color: var(--pst-color-text-base);
151-
}
152-
153-
/* Dark theme config */
154-
html[data-theme="dark"] {
155-
156-
.search__outer .search__result__content span,
157-
.search__outer .search__result__title span {
158-
/* Dark mode background color */
159-
/* background-color: var(--pst-color-muted-highlight); */
160-
color: var(--pst-color-primary);
161-
border-bottom-color: var(--pst-color-primary);
162-
}
163-
164-
/* Set color for the line between search text and results */
165-
.search__outer .bar:after,
166-
.search__outer .bar:before {
167-
background: var(--pst-color-primary);
168-
}
169-
170-
.rtd__search__credits {
171-
border: 1px solid var(--pst-color-border);
172-
border-width: 1px 0 0 0;
173-
}
174-
}
175-
176-
.rtd__search__credits {
177-
background-color: var(--pst-color-background);
178-
color: var(--pst-color-text-muted);
179-
/* So text is centered vertically */
180-
height: 37px;
181-
}
182-
183-
.rtd__search__credits a {
184-
color: var(--pst-color-link);
185-
}
186-
187-
.search__outer .search__result__content span,
188-
.search__outer .search__result__title span {
189-
border-bottom-color: var(--pst-color-text-base);
190-
}
191-
192-
/* Make sure "X" remains visible */
193-
.search__cross__img {
194-
fill: var(--pst-color-text-base);
195-
}
196-
197-
/* Prevent hover from actually changing the color by setting it to what it
198-
already is */
199-
.outer_div_page_results:hover,
200-
.search__result__box .active {
201-
background-color: var(--pst-color-on-background);
202-
}
203-
204-
/* End of styling of the RtD search extension's screen */

_static/js/pydata-search-close.js

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Script to allow use of readthedocs-sphinx-search extension with the pydata
2-
// theme
1+
// Script to allow use of readthedocs-sphinx-search extension with the pydata theme
32
//
43
// Based in part on:
54
// https://github.com/pydata/pydata-sphinx-theme/blob/v0.13.3/src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js#L167-L272
@@ -28,9 +27,8 @@ var findSearchInput = () => {
2827
}
2928
};
3029

31-
/** Function to hide the search field */
32-
var hideSearchField = () => {
33-
30+
// Hide Pydata theme's search
31+
var hidePydataSearch = () => {
3432
let input = findSearchInput();
3533
let searchPopupWrapper = document.querySelector(".search-button__wrapper");
3634
let hiddenInput = searchPopupWrapper.querySelector("input");
@@ -44,38 +42,65 @@ var hideSearchField = () => {
4442
}
4543
};
4644

47-
/** Add an event listener for hideSearchField() for Escape*/
45+
// Hide the ReadTheDocs search (addon version)
46+
function hideRtdSearch() {
47+
// Grab the search element from the DOM
48+
const searchElement = document.querySelector('readthedocs-search');
49+
searchElement.closeModal();
50+
}
51+
52+
// Hide any open search screens
53+
function hideSearch() {
54+
hidePydataSearch();
55+
hideRtdSearch();
56+
}
57+
58+
// Show the ReadTheDocs search (addon version)
59+
function showRtDSearch() {
60+
const searchElement = document.querySelector('readthedocs-search');
61+
searchElement.showModal();
62+
63+
// If we're displaying ReadTheDocs search, make sure to hide the Pydata theme's search
64+
hidePydataSearch();
65+
}
66+
67+
// Add event listeners for key strokes
4868
var addEventListenerForSearchKeyboard = () => {
4969
window.addEventListener(
5070
"keydown",
5171
(event) => {
5272
// Allow Escape key to hide the search field
5373
if (event.code == "Escape") {
54-
hideSearchField();
74+
hidePydataSearch();
75+
}
76+
77+
// Open the ReadTheDocs search modal when Ctrl+K is pressed
78+
if (event.ctrlKey && event.key === 'k') {
79+
event.preventDefault(); // Prevent default behavior of Ctrl+K
80+
showRtDSearch()
5581
}
5682
},
5783
true
5884
);
5985
};
6086

61-
/** Activate callbacks for search button popup */
87+
// Activate callbacks for search button popup
6288
var setupSearchButtons = () => {
6389
addEventListenerForSearchKeyboard();
90+
91+
// Add event listeners to elements with class "search-button__button"
92+
const searchButtons = document.querySelectorAll('.search-button__button');
93+
searchButtons.forEach(button => {
94+
button.addEventListener('click', showRtDSearch);
95+
});
6496
};
6597

6698
// Custom code to manage closing the RtD search dialog properly
6799
$(document).ready(function(){
68-
$(".search__cross").click(function(){
69-
hideSearchField();
70-
});
71-
$(".search__outer__wrapper.search__backdrop").click(function(){
72-
hideSearchField();
73-
});
74100
$(".search-button__overlay").click(function(){
75-
// Shouldn't be necessary since it's currently hidden by CSS, but just in
76-
// case
101+
// Shouldn't be necessary since it's currently hidden by CSS, but just in case
77102
console.log("Close by search-button__overlay");
78-
hideSearchField();
103+
hidePydataSearch();
79104
});
80105
});
81106

conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
'sphinx.ext.autodoc',
4141
'sphinx_copybutton',
4242
'sphinx_design',
43-
'sphinx_search.extension',
4443
'sphinx.ext.intersphinx',
4544
]
4645

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Babel==2.12.1
22
myst-parser==2.0.0
33
pydata-sphinx-theme==0.14.4
4-
readthedocs-sphinx-search==0.3.2
54
sphinx==7.2.6
65
sphinx-copybutton==0.5.2
76
sphinx-hoverxref==1.3.0

0 commit comments

Comments
 (0)