Skip to content

Commit 4e84385

Browse files
committedJan 15, 2022
Fix crate version parse bug
1 parent 1e05684 commit 4e84385

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed
 

‎extension/script/add-search-index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function () {
1+
(function() {
22
function sendSearchIndex() {
33
if (location.hostname === "docs.rs") { // docs.rs pages
44
// Parse crate info from location pathname.
@@ -10,8 +10,8 @@
1010
// If we parse the crate version from url is 'latest',
1111
// we should reparse it from the DOM to get the correct value.
1212
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];
1515
}
1616
window.postMessage({
1717
direction: "rust-search-extension",
@@ -58,7 +58,7 @@
5858
// Due to the new search-index.js on-demand load mode after PR #82310 has been merged.
5959
// We need to trigger a manual search-index.js load here.
6060
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.
6262
let searchIndexJs = window.searchIndexJS;
6363

6464
// For the older version, we still need to get it from the DOM.
@@ -68,12 +68,12 @@
6868
// then we should fallback to the "data-search-js", which is a
6969
// temporary stage in librustdoc.
7070
// 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;
7272
}
7373

7474
if (searchIndexJs) {
7575
let script = document.createElement('script');
76-
script.src = searchIndexJS;
76+
script.src = searchIndexJs;
7777
script.onload = sendSearchIndex;
7878
document.head.append(script);
7979
} else {

‎extension/script/docs-rs.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ document.addEventListener("DOMContentLoaded", () => {
6565
});
6666

6767
// Using separate event listener to avoid network requesting latency for feature flags menu enhancement.
68-
document.addEventListener("DOMContentLoaded", async () => {
68+
document.addEventListener("DOMContentLoaded", async() => {
6969
let menus = document.querySelector("form>.pure-menu-list:not(.pure-menu-right)");
7070
if (!menus) return;
7171

@@ -78,7 +78,7 @@ document.addEventListener("DOMContentLoaded", async () => {
7878
}
7979
});
8080

81-
document.addEventListener("DOMContentLoaded", async () => {
81+
document.addEventListener("DOMContentLoaded", async() => {
8282
let menus = document.querySelector("form>.pure-menu-list:not(.pure-menu-right)");
8383
if (!menus) return;
8484

@@ -89,8 +89,8 @@ document.addEventListener("DOMContentLoaded", async () => {
8989
// If we parse the crate version from url is 'latest',
9090
// we should reparse it from the DOM to get the correct value.
9191
if (crateVersion === 'latest') {
92-
let versionText = document.querySelector('nav.sidebar > div.block.version > p').textContent;
93-
crateVersion = versionText.split(' ')[1];
92+
let versionText = document.querySelector('.nav-container a.crate-name>.title').textContent;
93+
crateVersion = versionText.split('-')[1];
9494
}
9595

9696
// Exclude /crate/** pages
@@ -215,7 +215,7 @@ function insertAddToExtensionElement(state) {
215215
}
216216
}
217217

218-
window.addEventListener("message", function (event) {
218+
window.addEventListener("message", function(event) {
219219
if (event.source === window &&
220220
event.data &&
221221
event.data.direction === "rust-search-extension") {

0 commit comments

Comments
 (0)
Please sign in to comment.