Skip to content

Commit

Permalink
Fix crate version parse bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Folyd committed Jan 15, 2022
1 parent 1e05684 commit 4e84385
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions extension/script/add-search-index.js
@@ -1,4 +1,4 @@
(function () {
(function() {
function sendSearchIndex() {
if (location.hostname === "docs.rs") { // docs.rs pages
// Parse crate info from location pathname.
Expand All @@ -10,8 +10,8 @@
// If we parse the crate version from url is 'latest',
// we should reparse it from the DOM to get the correct value.
if (crateVersion === 'latest') {
let versionText = document.querySelector('nav.sidebar > div.block.version > p').textContent;
crateVersion = versionText.split(' ')[1];
let versionText = document.querySelector('.nav-container a.crate-name>.title').textContent;
crateVersion = versionText.split('-')[1];
}
window.postMessage({
direction: "rust-search-extension",
Expand Down Expand Up @@ -58,7 +58,7 @@
// Due to the new search-index.js on-demand load mode after PR #82310 has been merged.
// We need to trigger a manual search-index.js load here.
console.log("No search index found, start loading...")
// Since rust 1.58, we can get the searchIndexJs from window.searchIndexJs.
// Since rust 1.58, we can get the searchIndexJs from window.searchIndexJs.
let searchIndexJs = window.searchIndexJS;

// For the older version, we still need to get it from the DOM.
Expand All @@ -68,12 +68,12 @@
// then we should fallback to the "data-search-js", which is a
// temporary stage in librustdoc.
// Some crate could depends on this librustdoc. such as https://docs.rs/futures/0.3.14
searchIndexJS = (rustdocVars.attributes["data-search-index-js"] || rustdocVars.attributes["data-search-js"]).value;
searchIndexJs = (rustdocVars.attributes["data-search-index-js"] || rustdocVars.attributes["data-search-js"]).value;
}

if (searchIndexJs) {
let script = document.createElement('script');
script.src = searchIndexJS;
script.src = searchIndexJs;
script.onload = sendSearchIndex;
document.head.append(script);
} else {
Expand Down
10 changes: 5 additions & 5 deletions extension/script/docs-rs.js
Expand Up @@ -65,7 +65,7 @@ document.addEventListener("DOMContentLoaded", () => {
});

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

Expand All @@ -78,7 +78,7 @@ document.addEventListener("DOMContentLoaded", async () => {
}
});

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

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

// Exclude /crate/** pages
Expand Down Expand Up @@ -215,7 +215,7 @@ function insertAddToExtensionElement(state) {
}
}

window.addEventListener("message", function (event) {
window.addEventListener("message", function(event) {
if (event.source === window &&
event.data &&
event.data.direction === "rust-search-extension") {
Expand Down

0 comments on commit 4e84385

Please sign in to comment.