Skip to content

Fix latest version parsing for crates with hyphens in their name #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions extension/script/add-search-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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-container a.crate-name>.title').textContent;
crateVersion = versionText.split('-')[1];
let versionText = document.querySelector('nav.sidebar .version').textContent;
crateVersion = versionText.split(' ')[1];
}
window.postMessage({
direction: "rust-search-extension",
Expand Down Expand Up @@ -81,4 +81,4 @@
}

}
})();
})();
14 changes: 7 additions & 7 deletions extension/script/docs-rs.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ document.addEventListener("DOMContentLoaded", async() => {
let menus = document.querySelector("form>.pure-menu-list:not(.pure-menu-right)");
if (!menus) return;

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

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