mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-15 16:07:57 +00:00
Fix tide(~) search cause incorrect top crates data stats bug
This commit is contained in:
parent
ee09f850ca
commit
83f58def12
2 changed files with 12 additions and 2 deletions
2
core
2
core
|
@ -1 +1 @@
|
|||
Subproject commit bc6a52aa2bb1d81f3ddae132d10916e96fbe089d
|
||||
Subproject commit 3ad793a00ae84c11a80977ce2ba2dd13d32cc19f
|
|
@ -56,7 +56,17 @@ history.forEach(({ query, content, description, time }) => {
|
|||
if (["https://docs.rs", "https://crates.io", "https://lib.rs"].some(prefix => content.startsWith(prefix))) {
|
||||
let url = new URL(content);
|
||||
let pathname = url.pathname.replace("/crates/", "/").slice(1);
|
||||
let [crate, _] = pathname.split("/");
|
||||
let result = pathname.split("/");
|
||||
let crate;
|
||||
if (result.length >= 3) {
|
||||
// In this case, third element is the correct crate name.
|
||||
// e.g. https://docs.rs/~/*/async_std/stream/trait.Stream.html
|
||||
[_, __, crate] = result;
|
||||
} else {
|
||||
// In this case, the first element is the correct crate name.
|
||||
// e.g. https://crates.io/crates/async_std
|
||||
[crate] = result;
|
||||
}
|
||||
crate = crate.replace(/-/gi, "_");
|
||||
let counter = topCratesData[crate] || 0;
|
||||
topCratesData[crate] = counter + 1;
|
||||
|
|
Loading…
Reference in a new issue