Skip to content

Commit 7520201

Browse files
committed
Dependency injection ROOT_PATH
1 parent 0284ce4 commit 7520201

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/librustdoc/html/static/js/search.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ class RoaringBitmapBits {
10971097

10981098

10991099
class DocSearch {
1100-
constructor(rawSearchIndex) {
1100+
constructor(rawSearchIndex, rootPath) {
11011101
/**
11021102
* @type {Map<String, RoaringBitmap>}
11031103
*/
@@ -1118,6 +1118,7 @@ class DocSearch {
11181118
*/
11191119
this.typeNameIdMap = new Map();
11201120
this.ALIASES = new Map();
1121+
this.rootPath = rootPath;
11211122

11221123
/**
11231124
* Special type name IDs for searching by array.
@@ -1971,7 +1972,7 @@ class DocSearch {
19711972
};
19721973
}
19731974

1974-
function buildHrefAndPath(item) {
1975+
const buildHrefAndPath = item => {
19751976
let displayPath;
19761977
let href;
19771978
const type = itemTypes[item.ty];
@@ -1981,18 +1982,18 @@ class DocSearch {
19811982

19821983
if (type === "mod") {
19831984
displayPath = path + "::";
1984-
href = ROOT_PATH + path.replace(/::/g, "/") + "/" +
1985+
href = this.rootPath + path.replace(/::/g, "/") + "/" +
19851986
name + "/index.html";
19861987
} else if (type === "import") {
19871988
displayPath = item.path + "::";
1988-
href = ROOT_PATH + item.path.replace(/::/g, "/") + "/index.html#reexport." + name;
1989+
href = this.rootPath + item.path.replace(/::/g, "/") + "/index.html#reexport." + name;
19891990
} else if (type === "primitive" || type === "keyword") {
19901991
displayPath = "";
1991-
href = ROOT_PATH + path.replace(/::/g, "/") +
1992+
href = this.rootPath + path.replace(/::/g, "/") +
19921993
"/" + type + "." + name + ".html";
19931994
} else if (type === "externcrate") {
19941995
displayPath = "";
1995-
href = ROOT_PATH + name + "/index.html";
1996+
href = this.rootPath + name + "/index.html";
19961997
} else if (item.parent !== undefined) {
19971998
const myparent = item.parent;
19981999
let anchor = type + "." + name;
@@ -2019,13 +2020,13 @@ class DocSearch {
20192020
if (item.implDisambiguator !== null) {
20202021
anchor = item.implDisambiguator + "/" + anchor;
20212022
}
2022-
href = ROOT_PATH + path.replace(/::/g, "/") +
2023+
href = this.rootPath + path.replace(/::/g, "/") +
20232024
"/" + pageType +
20242025
"." + pageName +
20252026
".html#" + anchor;
20262027
} else {
20272028
displayPath = item.path + "::";
2028-
href = ROOT_PATH + item.path.replace(/::/g, "/") +
2029+
href = this.rootPath + item.path.replace(/::/g, "/") +
20292030
"/" + type + "." + name + ".html";
20302031
}
20312032
return [displayPath, href, `${exactPath}::${name}`];
@@ -3901,9 +3902,9 @@ function updateCrate(ev) {
39013902
function initSearch(searchIndx) {
39023903
rawSearchIndex = searchIndx;
39033904
if (typeof window !== "undefined") {
3904-
docSearch = new DocSearch(rawSearchIndex);
3905+
docSearch = new DocSearch(rawSearchIndex, ROOT_PATH);
39053906
} else if (typeof exports !== "undefined") {
3906-
docSearch = new DocSearch(rawSearchIndex);
3907+
docSearch = new DocSearch(rawSearchIndex, ROOT_PATH);
39073908
exports.docSearch = docSearch;
39083909
exports.parseQuery = DocSearch.parseQuery;
39093910
}

0 commit comments

Comments
 (0)