From 83f58def1200e355e08dfa7e7e35bd2d2d20386f Mon Sep 17 00:00:00 2001 From: Folyd Date: Wed, 27 May 2020 00:17:57 +0800 Subject: [PATCH] Fix tide(~) search cause incorrect top crates data stats bug --- core | 2 +- extension/stats/index.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core b/core index bc6a52a..3ad793a 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit bc6a52aa2bb1d81f3ddae132d10916e96fbe089d +Subproject commit 3ad793a00ae84c11a80977ce2ba2dd13d32cc19f diff --git a/extension/stats/index.js b/extension/stats/index.js index 61c6b1e..c26b1cd 100644 --- a/extension/stats/index.js +++ b/extension/stats/index.js @@ -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;