-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtc.bb
More file actions
executable file
·29 lines (24 loc) · 944 Bytes
/
tc.bb
File metadata and controls
executable file
·29 lines (24 loc) · 944 Bytes
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
#!/usr/bin/env bb
(require '[clojure.string :as str]
'[clojure.java.io :as io])
(let [filename (first *command-line-args*)]
(if-not filename
(do
(println "Usage: ./toc.bb <markdown-file>")
(System/exit 1))
(let [day-counter (atom 0)
quote-block (atom false)]
(with-open [rdr (io/reader filename)]
(doseq [line (line-seq rdr)]
(cond
(str/starts-with? line "```")
(swap! quote-block not)
(and (not @quote-block) (str/starts-with? line "# "))
(let [title (str/trim (subs line 2))
day (swap! day-counter inc)
day-str (format "%02d" day)]
(println (str "* [" title "](./day" day-str ".md)")))
(and (not @quote-block) (str/starts-with? line "## "))
(let [title (str/trim (subs line 3))]
(println (str " * " title)))
:else nil))))))