-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcreateToc.ts
40 lines (31 loc) · 1.22 KB
/
createToc.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
// deno run --allow-read ./tools/createToc.ts ./articles/productivity-weekly-20230726.md
import { TocBuilder } from "./libs/Toc.ts";
import { marked, matter } from "./deps.ts";
const main = async () => {
if (Deno.args[0] === undefined) {
throw new Error("引数にマークダウンのパスを指定してください");
}
// 引数でマークダウンのパスを受け取る
const markdown = await Deno.readTextFile(Deno.args[0]);
const content = matter(markdown).content;
const lexer = new marked.Lexer();
// マークダウンをパースする
const tokens = lexer.lex(content);
const tocBuilder = new TocBuilder();
tocBuilder.registerHeadings(tokens);
tocBuilder.registerLists(tokens);
const toc = tocBuilder.build();
console.log(`
1. 出てきた文字列をコピーする
2. Slack のキャンバスを新規作成する。
3. 作成したキャンバスに Command + Shift + p で貼り付ける
4. 貼った文字列を選択し、チェックボックスに変換する
---
※ネタのカテゴリや順序は執筆者の独断で変更してもらって構いません
`);
console.log(toc);
};
// import された際は main() を実行しない
if (import.meta.main) {
await main();
}