From 5fc1cc6602ac03d05ce004d8d4d9c712242f318b Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 12 May 2020 22:49:35 -0700 Subject: Output formatting fixups --- z.scm | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'z.scm') 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 #: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)])) -- cgit v1.2.3