62
62
63
63
// For the older version, we still need to get it from the DOM.
64
64
if ( ! searchIndexJs ) {
65
- let rustdocVars = document . getElementById ( "rustdoc-vars" ) ;
66
- if ( rustdocVars ) {
67
- // If we can't get the search index via "data-search-index-js",
68
- // then we should fallback to the "data-search-js", which is a
69
- // temporary stage in librustdoc.
70
- // Some crate could depends on this librustdoc. such as https://docs.rs/futures/0.3.14
71
- searchIndexJs = ( rustdocVars . attributes [ "data- search-index-js" ] || rustdocVars . attributes [ "data-search-js" ] ) . value ;
72
- }
65
+ // If we can't get the search index via "data-search-index-js",
66
+ // then we should fallback to the "data-search-js", which is a
67
+ // temporary stage in librustdoc.
68
+ // Some crate could depends on this librustdoc. such as https://docs.rs/futures/0.3.14
69
+ //
70
+ // This PR https://github.com/rust-lang/rust/pull/98124 use another way to load search-index:
71
+ // by concatenating the paths to get a full search-index.js file, see resourcePath() function.
72
+ searchIndexJs = getVar ( 'search-index-js' ) || getVar ( 'search-js' ) || resourcePath ( "search-index" , ".js" ) ;
73
73
}
74
74
75
75
if ( searchIndexJs ) {
81
81
console . error ( "Sorry, no search index found." ) ;
82
82
}
83
83
}
84
- } ) ( ) ;
84
+ } ) ( ) ;
85
+
86
+ // ======== Following function mirrored to librustdoc main.js ========
87
+
88
+ // Get rustdoc variable from DOM.
89
+ function getVar ( name ) {
90
+ const el = document . getElementById ( "rustdoc-vars" ) ;
91
+ if ( el ) {
92
+ const dataVar = el . attributes [ "data-" + name ] ;
93
+ if ( dataVar ) {
94
+ return dataVar . value ;
95
+ }
96
+ }
97
+ return null
98
+ }
99
+
100
+ function resourcePath ( basename , extension ) {
101
+ return getVar ( "root-path" ) + basename + getVar ( "resource-suffix" ) + extension
102
+ }
0 commit comments