|
1 |
| -(function () { |
| 1 | +(function() { |
2 | 2 | function sendSearchIndex() {
|
3 | 3 | if (location.hostname === "docs.rs") { // docs.rs pages
|
4 | 4 | // Parse crate info from location pathname.
|
|
10 | 10 | // If we parse the crate version from url is 'latest',
|
11 | 11 | // we should reparse it from the DOM to get the correct value.
|
12 | 12 | if (crateVersion === 'latest') {
|
13 |
| - let versionText = document.querySelector('nav.sidebar > div.block.version > p').textContent; |
14 |
| - crateVersion = versionText.split(' ')[1]; |
| 13 | + let versionText = document.querySelector('.nav-container a.crate-name>.title').textContent; |
| 14 | + crateVersion = versionText.split('-')[1]; |
15 | 15 | }
|
16 | 16 | window.postMessage({
|
17 | 17 | direction: "rust-search-extension",
|
|
58 | 58 | // Due to the new search-index.js on-demand load mode after PR #82310 has been merged.
|
59 | 59 | // We need to trigger a manual search-index.js load here.
|
60 | 60 | console.log("No search index found, start loading...")
|
61 |
| - // Since rust 1.58, we can get the searchIndexJs from window.searchIndexJs. |
| 61 | + // Since rust 1.58, we can get the searchIndexJs from window.searchIndexJs. |
62 | 62 | let searchIndexJs = window.searchIndexJS;
|
63 | 63 |
|
64 | 64 | // For the older version, we still need to get it from the DOM.
|
|
68 | 68 | // then we should fallback to the "data-search-js", which is a
|
69 | 69 | // temporary stage in librustdoc.
|
70 | 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; |
| 71 | + searchIndexJs = (rustdocVars.attributes["data-search-index-js"] || rustdocVars.attributes["data-search-js"]).value; |
72 | 72 | }
|
73 | 73 |
|
74 | 74 | if (searchIndexJs) {
|
75 | 75 | let script = document.createElement('script');
|
76 |
| - script.src = searchIndexJS; |
| 76 | + script.src = searchIndexJs; |
77 | 77 | script.onload = sendSearchIndex;
|
78 | 78 | document.head.append(script);
|
79 | 79 | } else {
|
|
0 commit comments