File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -290,7 +290,37 @@ function txtSearchChange(event) {
290
290
matchedResults . sort ( ( a , b ) => b . score - a . score ) ;
291
291
292
292
// Add the "Search for..." item at the top
293
- resultPanel . innerHTML = `<div class='search_result_item' data-type='search'><a href="search.html?q=${ encodeURIComponent ( searchText ) } "><span>Search Documentation for "${ escapeHTML ( searchText ) } "</span></a></div>` ;
293
+ // Get the URL root from the RTD documentation options
294
+ let urlRoot = DOCUMENTATION_OPTIONS . URL_ROOT ;
295
+
296
+ // If the URL root is not set (e.g. for local development), get the script path and go up one directory
297
+ if ( urlRoot ) {
298
+ urlRoot = urlRoot + '/' ;
299
+ } else {
300
+ // If we're already on the search page, use relative path
301
+ if ( window . location . pathname . endsWith ( '/search.html' ) ) {
302
+ urlRoot = '' ;
303
+ } else {
304
+ try {
305
+ const scriptSrc = document . currentScript ? document . currentScript . src :
306
+ ( document . scripts [ document . scripts . length - 1 ] ? document . scripts [ document . scripts . length - 1 ] . src : '' ) ;
307
+ if ( scriptSrc ) {
308
+ const url = new URL ( scriptSrc ) ;
309
+ const pathParts = url . pathname . split ( '/' ) ;
310
+ pathParts . pop ( ) ; // Remove the script filename
311
+ pathParts . pop ( ) ; // Go up one directory from _static
312
+ urlRoot = url . origin + pathParts . join ( '/' ) + '/' ;
313
+ } else {
314
+ urlRoot = '' ;
315
+ }
316
+ } catch ( e ) {
317
+ urlRoot = '' ;
318
+ }
319
+ }
320
+ }
321
+
322
+ searchUrl = urlRoot + 'search.html' ;
323
+ resultPanel . innerHTML = `<div class='search_result_item' data-type='search'><a href="${ searchUrl } ?q=${ encodeURIComponent ( searchText ) } "><span>Search Documentation for "${ escapeHTML ( searchText ) } "</span></a></div>` ;
294
324
295
325
// Add the rest of the results
296
326
resultPanel . innerHTML += matchedResults . map ( r =>
Original file line number Diff line number Diff line change 1
- < div id ="searchKeybindHint " style ="visibility: hidden; text-align: center; font-size: 0.75em; margin-bottom: 4px; color: var(--color-foreground-muted); "> Press Ctrl+Enter to search page contents</ div >
2
1
< div id ="tocSearchPanel ">
3
2
< div id ="tocSearchPanelInner ">
4
3
< input type ="text " id ="txtSearch " placeholder ="Search... " autocomplete ="off " />
5
4
</ div >
6
5
< div id ="tocSearchResult " style ="display: none; "> </ div >
7
- </ div >
6
+ </ div >
You can’t perform that action at this time.
0 commit comments