Skip to content

Commit da193e6

Browse files
committed
Support the new search-index loading, see rust-lang/rust#98124
1 parent 2301f9a commit da193e6

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

extension/script/add-search-index.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@
6262

6363
// For the older version, we still need to get it from the DOM.
6464
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");
7373
}
7474

7575
if (searchIndexJs) {
@@ -81,4 +81,22 @@
8181
console.error("Sorry, no search index found.");
8282
}
8383
}
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

Comments
 (0)