forked from outline/alfred-outline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (28 loc) · 784 Bytes
/
index.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
const path = require('path');
const alfy = require('alfy');
const protocolAndHost = `https://${process.env.domain || "app.getoutline.com"}`;
const results = await alfy.fetch(`${protocolAndHost}/api/documents.search`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.apiToken}`,
"Content-Type": "application/json",
},
body: {
query: alfy.input
}
});
let items = results.data.map(result => ({
title: result.document.title,
subtitle: result.context.replace(/\<\/?b\>/g, ''),
arg: `${protocolAndHost}${result.document.url}`,
icon: {
path: path.join(__dirname, "document.png")
}
}));
if (!items.length) {
items = [{
title: "No results - go to Outline homepage",
arg: `${protocolAndHost}/home`
}];
}
alfy.output(items);