mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 15:47:12 +00:00
Add nightly search index
This commit is contained in:
parent
a42bb973e8
commit
756b96dca3
5 changed files with 59 additions and 10 deletions
|
@ -212,6 +212,22 @@ chrome.runtime.setUninstallURL(
|
|||
|
||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
switch (message.action) {
|
||||
// Nightly:* action is exclusive to nightly docs event
|
||||
case "nightly:check" : {
|
||||
let currentNightlyVersion = NightlyDocManager.getNightlyVersion();
|
||||
if (currentNightlyVersion && Date.parse(currentNightlyVersion) >= Date.parse(message.nightlyVersion)) {
|
||||
sendResponse({state: 'latest'});
|
||||
} else {
|
||||
sendResponse({state: 'outdated'});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "nightly:add" : {
|
||||
NightlyDocManager.setNightlyDocs(message.searchIndex);
|
||||
NightlyDocManager.setNightlyVersion(message.nightlyVersion);
|
||||
sendResponse(true);
|
||||
break;
|
||||
}
|
||||
case "check": {
|
||||
let crates = CrateDocSearchManager.getCrates();
|
||||
sendResponse(crates[message.crateName]);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(function() {
|
||||
(function () {
|
||||
// Remove needless crate's search index, such as core, alloc, etc
|
||||
function cleanSearchIndex() {
|
||||
let searchIndex = {};
|
||||
|
@ -7,9 +7,9 @@
|
|||
searchIndex['proc_macro'] = window.searchIndex['proc_macro'];
|
||||
return searchIndex;
|
||||
}
|
||||
|
||||
|
||||
let p = document.querySelector('nav.sidebar>div.version>p');
|
||||
let nightlyVersion = p.textContent;
|
||||
let nightlyVersion = p.textContent.match(/\d{4}-\d{1,2}-\d{1,2}/)[0];
|
||||
window.postMessage({
|
||||
direction: "rust-search-extension:nightly",
|
||||
message: {
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
document.addEventListener("DOMContentLoaded", () => {
|
||||
let p = document.querySelector('nav.sidebar>div.version>p');
|
||||
|
||||
console.log("nightly std...", p.textContent);
|
||||
let nightlyVersion = p.textContent.match(/\d{4}-\d{1,2}-\d{1,2}/)[0];
|
||||
|
||||
chrome.runtime.sendMessage({nightlyVersion, action: "nightly:check"}, response => {
|
||||
console.log('response:', response);
|
||||
if (response.state !== 'latest') {
|
||||
injectScripts(["script/add-nightly-search-index.js"]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
window.addEventListener("message", function(event) {
|
||||
window.addEventListener("message", function (event) {
|
||||
if (event.source === window &&
|
||||
event.data &&
|
||||
event.data.direction === "rust-search-extension:nightly") {
|
||||
chrome.runtime.sendMessage({action: "add", ...event.data.message},
|
||||
chrome.runtime.sendMessage({action: "nightly:add", ...event.data.message},
|
||||
(response) => {
|
||||
console.log(response);
|
||||
}
|
||||
|
|
27
extension/search/docs/nightly.js
Normal file
27
extension/search/docs/nightly.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
class NightlySearch extends DocSearch {
|
||||
constructor(searchIndex) {
|
||||
super("std", searchIndex);
|
||||
}
|
||||
|
||||
get rootPath() {
|
||||
return "https://doc.rust-lang.org/nightly/";
|
||||
}
|
||||
}
|
||||
|
||||
class NightlyDocManager {
|
||||
static getNightlyVersion() {
|
||||
return localStorage.getItem('nightly-version') || null;
|
||||
}
|
||||
|
||||
static setNightlyVersion(version) {
|
||||
localStorage.setItem('nightly-version', version);
|
||||
}
|
||||
|
||||
static getNightlyDocs() {
|
||||
return JSON.parse(localStorage.getItem('nightly-docs') || "{}");
|
||||
}
|
||||
|
||||
static setNightlyDocs(docs) {
|
||||
localStorage.setItem('nightly-docs', JSON.stringify(docs));
|
||||
}
|
||||
}
|
|
@ -7,17 +7,17 @@ local js_files(name, files) = ['%s/%s.js' % [name, file] for file in files];
|
|||
|
||||
local json = manifest.new(
|
||||
name='Rust Search Extension',
|
||||
version='0.10.0',
|
||||
version='0.11.0',
|
||||
keyword='rs',
|
||||
description='The ultimate search extension for Rust',
|
||||
)
|
||||
.addIcons(icons())
|
||||
.addWebAccessibleResources('script/add-search-index.js')
|
||||
.addWebAccessibleResources(['script/add-search-index.js', 'script/add-nightly-search-index.js'])
|
||||
.addBackgroundScripts(
|
||||
['settings.js', 'deminifier.js']
|
||||
)
|
||||
.addBackgroundScripts(js_files('search', ['book', 'crate', 'attribute', 'lint']))
|
||||
.addBackgroundScripts(js_files('search/docs', ['base', 'std', 'crate-doc']))
|
||||
.addBackgroundScripts(js_files('search/docs', ['base', 'std', 'nightly', 'crate-doc']))
|
||||
.addBackgroundScripts(js_files('index', ['attributes', 'books', 'crates', 'std-docs', 'lints', 'labels', 'commands']))
|
||||
.addBackgroundScripts(js_files('command', ['label', 'help', 'stable']))
|
||||
.addBackgroundScripts('main.js')
|
||||
|
|
Loading…
Reference in a new issue