-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.ts
executable file
·72 lines (65 loc) · 1.34 KB
/
extension.ts
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
64
65
66
67
68
69
70
71
72
if (Deno.args.length === 0) {
const manifest = {
title: "Slides",
commands: [
{
name: "show",
title: "Show a slide",
mode: "view",
params: [
{
name: "path",
type: "string",
required: true,
},
{
name: "index",
type: "string",
},
],
},
],
};
console.log(JSON.stringify(manifest));
Deno.exit(0);
}
if (Deno.args[0] == "show") {
const { params } = await new Response(Deno.stdin.readable).json();
const markdown = Deno.readTextFileSync(params.path);
const sections = markdown.split("\n---\n");
const index = params.index || 0;
const section = sections[index];
const actions = [];
if (index < sections.length - 1) {
actions.push({
title: "Next",
key: "n",
onAction: {
type: "reload",
params: {
path: params.path,
index: index + 1,
},
},
});
}
if (index > 0) {
actions.push({
title: "Previous",
key: "p",
onAction: {
type: "reload",
params: {
path: params.path,
index: index - 1,
},
},
});
}
const detail = {
type: "detail",
markdown: section.trim(),
actions: actions,
};
console.log(JSON.stringify(detail));
}