summaryrefslogtreecommitdiff
path: root/z.scm
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-05-12 22:49:35 -0700
committerBen Sima <ben@bsima.me>2020-05-12 22:49:35 -0700
commit5fc1cc6602ac03d05ce004d8d4d9c712242f318b (patch)
treeec5843efd3e80c7890a37bcb47149ffd214978eb /z.scm
parentbc83c64067f5ef2b7e6e1bf9b7b49dbb12b9ddba (diff)
Output formatting fixups
Diffstat (limited to 'z.scm')
-rw-r--r--z.scm39
1 files changed, 23 insertions, 16 deletions
diff --git a/z.scm b/z.scm
index 1739d34..b8bcbfe 100644
--- a/z.scm
+++ b/z.scm
@@ -53,7 +53,7 @@
;; base 36.
(define (id->string id)
- (number->string id 36))
+ (fmt "~36,3'0r" id))
(define (string->id s)
(string->number s 36))
@@ -140,17 +140,17 @@ NL < '\n'
[_ '()])))
(define (parse-content node-tree)
- (-> tree second second))
+ (-> node-tree second second))
(define (load-node id)
(let* ([node-tree (->> id id->path readlines (match-pattern node) peg:tree)]
[meta (parse-meta node-tree)])
(make <node>
#:id id
- #:title (assoc "title" meta)
- #:created (assoc "created" meta)
+ #:title (assoc-ref meta "title")
+ #:created (assoc-ref meta "created")
#:tags (->> meta
- (filter (/. P (equal? car P "tag")))
+ (filter (/. P (equal? (car P) "tag")))
(map cdr))
#:content (parse-content node-tree))))
@@ -246,7 +246,8 @@ NL < '\n'
(lambda (id)
`(li (a (@ (href ,(fmt "/node/~a" id)))
,(fmt "~a: ~a"
- id (title (load-node id))))))))))]
+ (id->string id)
+ (title (load-node id))))))))))]
[("node" id)
(let* ([node (load-node (string->id id))]
[txt (or (content node) "")])
@@ -266,8 +267,8 @@ NL < '\n'
`((ul ,@(turn ids
(lambda [id]
`(li (a (@ (href ,(fmt "/node/~a" id)))
- ,(fmt "~a: ~a"
- id
+ ,(fmt "~a: ~a"
+ (id->string id)
(title (load-node id)))))))))))]
[_ (respond "not found")]))
@@ -300,21 +301,27 @@ where 'command' is:
(exit EXIT_SUCCESS))]
[("ls")
(turn (list-nodes)
- (lambda (id)
- (pr id) (pr ": ")
- (prn (title (load-node id)))))]
+ (lambda (id)
+ (format #t "~a: ~a\n"
+ (id->string id)
+ (title (load-node id)))))]
[("tagged" tag)
(begin
(reindex)
(turn (tagged tag)
- (lambda (id)
- (pr id)
- (pr ": ")
- (pr (title (load-node id))))))]
+ (lambda (id)
+ (format #t "~a: ~a\n"
+ (id->string id)
+ (title (load-node id))))))]
[("tags")
(begin
(reindex)
- (map prn (dict.keys *tags*)))]
+ (turn (dict.keys *tags*)
+ (lambda (tag)
+ (format #t
+ "(~a) ~a\n"
+ (count (const #t) (dict.get *tags* tag))
+ tag))))]
[("web") (serve)]
[("web" port) (serve #:port (string->number port))]
[_ (usage)]))