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) {
290290 matchedResults . sort ( ( a , b ) => b . score - a . score ) ;
291291
292292 // 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>` ;
294324
295325 // Add the rest of the results
296326 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 >
21< div id ="tocSearchPanel ">
32 < div id ="tocSearchPanelInner ">
43 < input type ="text " id ="txtSearch " placeholder ="Search... " autocomplete ="off " />
54 </ div >
65 < div id ="tocSearchResult " style ="display: none; "> </ div >
7- </ div >
6+ </ div >
You can’t perform that action at this time.
0 commit comments