Change book, yet and tool to SimpleCommand

This commit is contained in:
Folyd 2020-06-21 12:08:38 +08:00
parent b58df9dbc1
commit 3553ebb0a6
6 changed files with 11 additions and 97 deletions

2
core

@ -1 +1 @@
Subproject commit 3531e74d974c799bcda24011fb323753d63b12e5
Subproject commit 98984d4f6a788c5c4612a2098b7e1ee3cdbc4e80

View file

@ -1,38 +0,0 @@
class BookCommand extends Command {
constructor() {
super("book", "Show all Rust official books.");
}
onExecute(arg) {
const books = [
["The Rust Programming Language", "https://doc.rust-lang.org/stable/book/"],
["Rust Async Book", "https://rust-lang.github.io/async-book/"],
["Rust Edition Guide Book", "https://doc.rust-lang.org/stable/edition-guide/"],
["The Cargo Book", "https://doc.rust-lang.org/cargo/index.html"],
["Rust and WebAssembly Book", "https://rustwasm.github.io/docs/book/"],
["The Embedded Rust Book", "https://rust-embedded.github.io/book/"],
["The Rust Cookbook", "https://rust-lang-nursery.github.io/rust-cookbook/"],
["Command line apps in Rust", "https://rust-cli.github.io/book/index.html"],
["Rust by Example", "https://doc.rust-lang.org/stable/rust-by-example/"],
["Rust RFC", "https://rust-lang.github.io/rfcs/"],
["The Rust Doc Book", "https://doc.rust-lang.org/rustdoc/index.html"],
["The rustc Book", "https://doc.rust-lang.org/rustc/index.html"],
["Guide to Rustc Development", "https://rustc-dev-guide.rust-lang.org/"],
["The Rust Reference", "https://doc.rust-lang.org/reference/index.html"],
["The Rustonomicon", "https://doc.rust-lang.org/nomicon/index.html"],
["The Unstable Book", "https://doc.rust-lang.org/unstable-book/index.html"],
["Rust bindgen User Guide", "https://rust-lang.github.io/rust-bindgen/"],
["The wasm-bindgen Guide", "https://rustwasm.github.io/docs/wasm-bindgen/"],
["Rust API Guidelines", "https://rust-lang.github.io/api-guidelines/"],
["Rust Fuzz Book", "https://rust-fuzz.github.io/book/"],
["Rust Forge Book", "https://forge.rust-lang.org/"],
];
return books
.filter(item => !arg || item[0].toLowerCase().indexOf(arg) > -1)
.map(([name, url]) => {
return {
content: url,
description: `${c.match(name)} - ${c.dim(url)}`,
}
});
}
}

View file

@ -1,22 +0,0 @@
class ToolCommand extends Command {
constructor() {
super("tool", "Show some most useful Rust tools.");
}
onExecute(arg) {
const tools = [
["Rust Playground", "https://play.rust-lang.org/"],
["cheats.rs", "https://cheats.rs/"],
["caniuse.rs", "https://caniuse.rs/"],
["Macro Railroad ", "https://lukaslueg.github.io/macro_railroad_wasm_demo/"],
];
return tools
.filter(item => !arg || item[0].toLowerCase().indexOf(arg) > -1)
.map(([name,url]) => {
return {
content: url,
description: `${c.match(name)} - ${c.dim(url)}`
}
})
}
}

View file

@ -1,26 +0,0 @@
class YetCommand extends Command {
constructor() {
super("yet", "Show all Are We Yet websites.")
}
onExecute(arg) {
const areweyet = [
["Are we async yet?", "Asynchronous I/O in Rust", "https://areweasyncyet.rs"],
["Are we audio yet?", "Audio related development in Rust", "https://areweaudioyet.com"],
["Are we game yet?", "Rust game development", "http://arewegameyet.com"],
["Are we GUI yet?", "Rust GUI development", "http://areweguiyet.com"],
["Are we IDE yet?", "Rust development environments", "http://areweideyet.com"],
["Are we learning yet?", "Rust machine learning ecosystem", "http://www.arewelearningyet.com"],
["Are we web yet?", "Rust libraries for web development", "http://arewewebyet.org"],
["Are we podcast yet?", "Rust Are We Podcast Yet", "https://soundcloud.com/arewepodcastyet"],
];
return areweyet
.filter(item => !arg || item[0].toLowerCase().indexOf(arg) > -1)
.map(([title, description, content]) => {
return {
content,
description: `${title} - ${c.dim(description)}`,
}
});
}
}

View file

@ -7,10 +7,10 @@ const stdSearcher = new StdSearch(searchIndex);
const crateDocSearchManager = new CrateDocSearchManager();
const commandManager = new CommandManager(
new HelpCommand(),
new BookCommand(),
new YetCommand(),
new SimpleCommand('book', 'Show all Rust official books.', commandsIndex['book']),
new SimpleCommand('yet', 'Show all Are We Yet websites.', commandsIndex['yet']),
new SimpleCommand('tool', 'Show some most useful Rust tools.', commandsIndex['tool']),
new StableCommand(),
new ToolCommand(),
new LabelCommand(labelsIndex),
new HistoryCommand(),
);
@ -24,7 +24,7 @@ let formatDoc = (index, doc) => {
description += ` - ${c.dim(c.escape(doc.desc))}`;
}
return { content: doc.href, description };
return {content: doc.href, description};
};
omnibox.bootstrap({
@ -96,10 +96,10 @@ omnibox.addPrefixQueryEvent("!", {
onFormat: (index, crate, query) => {
let content;
let description;
if (query.startsWith("!!!")){
if (query.startsWith("!!!")) {
content = `${REDIRECT_URL}?crate=${crate.id}`;
description = `${c.capitalize("repository")}: ${c.match(crate.id)} v${crate.version} - ${c.dim(c.escape(crate.description))}`;
} else if(query.startsWith("!!")) {
} else if (query.startsWith("!!")) {
content = `https://docs.rs/${crate.id}`;
description = `${c.capitalize("docs.rs")}: ${c.match(crate.id)} v${crate.version} - ${c.dim(c.escape(crate.description))}`
} else {
@ -117,10 +117,10 @@ omnibox.addPrefixQueryEvent("!", {
let encode = encodeURIComponent(keyword);
let content;
let description;
if(query.startsWith("!!!")) {
if (query.startsWith("!!!")) {
content = "https://github.com/search?q=" + encode;
description = "Search Rust crates for " + c.match(keyword) + " on https://github.com";
} else if(query.startsWith("!!")) {
} else if (query.startsWith("!!")) {
content = "https://docs.rs/releases/search?query=" + encode;
description = "Search Rust crates for " + c.match(keyword) + " on https://docs.rs";
} else {

View file

@ -18,8 +18,8 @@ local json = manifest.new(
)
.addBackgroundScripts(js_files('search', ['book', 'crate', 'attribute', 'lint']))
.addBackgroundScripts(js_files('search/docs', ['base', 'std', 'crate-doc']))
.addBackgroundScripts(js_files('index', ['books', 'crates', 'std-docs', 'lints', 'labels']))
.addBackgroundScripts(js_files('command', ['label', 'tool', 'book', 'help', 'yet', 'stable']))
.addBackgroundScripts(js_files('index', ['books', 'crates', 'std-docs', 'lints', 'labels', 'commands']))
.addBackgroundScripts(js_files('command', ['label', 'help', 'stable']))
.addBackgroundScripts('main.js')
.addContentScript(
matches=['*://docs.rs/*'],