Skip to content

Commit

Permalink
Feat rustc search appendix
Browse files Browse the repository at this point in the history
  • Loading branch information
Folyd committed Nov 25, 2022
1 parent 7809eaa commit 76077a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions extension/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,20 @@ function getPlatformOs() {
},
onAppend: (query) => {
query = query.replaceAll("/", "").trim();
let appendix = {
content: rustcSearcher.getSearchUrl(query),
description: `Search nightly rustc docs ${c.match(query)} on ${rustcSearcher.getRootPath()}`,
};
if (rustcSearcher?.searchIndex?.length > 0) {
return [{
content: rustcSearcher.getSearchUrl(query),
description: `Search nightly rustc docs ${c.match(query)} on ${rustcSearcher.getRootPath()}`,
}];
return [appendix];
} else {
return [{
content: rustcSearcher.getRootPath(),
description: "To search nightly rustc docs, please open the nightly rustc docs page in advance.",
}];
return [
appendix,
{
content: rustcSearcher.getRootPath(),
description: "To search nightly rustc docs on the address bar, please open the nightly rustc docs page in advance.",
},
];
}
},
});
Expand Down
2 changes: 1 addition & 1 deletion extension/script/rustc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ document.addEventListener("DOMContentLoaded", () => {
});

window.addEventListener("message", function (event) {
console.log(event.data);
if (event.source === window &&
event.data &&
event.data.direction === "rust-search-extension:rustc") {
console.log(event.data);
let now = new Date();
let version = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
// rustc search index is a memory cache, therefore we don't use localStorage
Expand Down

0 comments on commit 76077a9

Please sign in to comment.