-
Notifications
You must be signed in to change notification settings - Fork 8
/
root.js
31 lines (28 loc) · 1021 Bytes
/
root.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const path = require('path')
const searches = require('./searches')
module.exports = (pluginContext) => {
return {
respondsTo: (query) => {
return query.length > 1
},
search: (query, env = {}) => {
const rootSearches = env.rootSearches || []
const prefixSearches = env.prefixSearches || {}
const searchKeys = [...Object.keys(searches), ...Object.keys(prefixSearches)]
const possiblePrefix = query.split(' ')[0]
if (searchKeys.indexOf(possiblePrefix) !== -1) return Promise.resolve([])
return Promise.resolve(
rootSearches.filter((prefix) => {
return searches[prefix] || prefixSearches[prefix]
}).map((prefix) => {
const search = searches[prefix] || prefixSearches[prefix]
return {
icon: search.icon || path.join('assets', prefix + '.png'),
title: 'Search ' + search.name + ' for ' + query,
value: search.url + encodeURIComponent(query)
}
})
)
},
}
}