Skip to content

Commit dafa48a

Browse files
authored
Merge pull request #147 from rrbutani/master
Fix latest version parsing for crates with hyphens in their name
2 parents dcacb8d + 9f0c2b1 commit dafa48a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

extension/script/add-search-index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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-container a.crate-name>.title').textContent;
14-
crateVersion = versionText.split('-')[1];
13+
let versionText = document.querySelector('nav.sidebar .version').textContent;
14+
crateVersion = versionText.split(' ')[1];
1515
}
1616
window.postMessage({
1717
direction: "rust-search-extension",
@@ -81,4 +81,4 @@
8181
}
8282

8383
}
84-
})();
84+
})();

extension/script/docs-rs.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ document.addEventListener("DOMContentLoaded", async() => {
8282
let menus = document.querySelector("form>.pure-menu-list:not(.pure-menu-right)");
8383
if (!menus) return;
8484

85-
// Since this PR (https://github.com/rust-lang/docs.rs/pull/1527) merged,
85+
// Since this PR (https://github.com/rust-lang/docs.rs/pull/1527) merged,
8686
// the latest version path has changed:
8787
// from https://docs.rs/tokio/1.14.0/tokio/ to https://docs.rs/tokio/latest/tokio/
8888
//
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-container a.crate-name>.title').textContent;
93-
crateVersion = versionText.split('-')[1];
92+
let versionText = document.querySelector('nav.sidebar .version').textContent;
93+
crateVersion = versionText.split(' ')[1];
9494
}
9595

9696
// Exclude /crate/** pages
@@ -174,9 +174,9 @@ function insertAddToExtensionElement(state) {
174174
let content, iconAttributes, iconFile;
175175
if (state === "latest") {
176176
content = `<p>
177-
You already added this crate (v${installedVersion}). Click again to remove it.
178-
Or click
179-
<span id="rse-here" style="text-decoration: underline; cursor: pointer">here</span>
177+
You already added this crate (v${installedVersion}). Click again to remove it.
178+
Or click
179+
<span id="rse-here" style="text-decoration: underline; cursor: pointer">here</span>
180180
to manage all your indexed crates.
181181
</p>`;
182182
iconAttributes = `class="fa-svg fa-svg-fw" style="color:green"`;
@@ -236,4 +236,4 @@ window.addEventListener("message", function(event) {
236236
}
237237
);
238238
}
239-
});
239+
});

0 commit comments

Comments
 (0)