-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchNotebook.js
63 lines (55 loc) · 1.55 KB
/
searchNotebook.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const arvish = require('arvish')
const _ = require('lodash')
const {
handleInput,
replaceAll
} = require('./utils')
const LogManager = require('./logManager')
const isTravis = require('is-travis')
require('./checkApiKey')
!isTravis && require('dotenv').config()
const api = require('./api')(process.env.oauthToken)
require('./checkIsCaching')
const arvishInput = replaceAll(handleInput(arvish.input), '\\', '')
async function searchNotebook (listNotebooks) {
let items = listNotebooks
if (arvishInput) {
items = _.filter(listNotebooks, notebook => {
// Need to normalize arvish.input and match the encoding so that users can search normally in Korean
const notebookName = notebook.name.toLowerCase()
const input = arvishInput.normalize().toLowerCase()
if (!notebookName.includes(input)) {
return false
}
return true
})
}
items = _.orderBy(items, ['name'], ['asc'])
return _.map(items, (notebook) => {
return {
title: notebook.name,
arg: `notebook:"${notebook.name}" `,
valid: true,
autocomplete: notebook.name,
subtitle: `Created time: ${new Date(notebook.serviceCreated).toUTCString()}`,
icon: {
path: './icon/searchIcon.png'
},
text: {
copy: notebook.name,
largetype: notebook.name
},
variables: {
notebookGuid: notebook.guid
}
}
})
}
(async function () {
arvish.output(await api.listNotebooks(
{
callback: searchNotebook
}
))
LogManager.write(`enb ${handleInput(arvish.input)}`)
})()