diff options
author | Ben Sima <ben@bsima.me> | 2020-05-11 15:16:59 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-05-11 15:16:59 -0700 |
commit | 29e88e1dfe173a5cf86dc952a561cefd6ae866e0 (patch) | |
tree | f8b3ba590cc2bca5d8420fe0ae4ab43965bf7f71 | |
parent | 7f5a5970c8e8625870679e449b2e91a5cb3c6afc (diff) |
Add 'web port' argument, and some more page/templating
-rw-r--r-- | z.scm | 40 |
1 files changed, 25 insertions, 15 deletions
@@ -150,7 +150,7 @@ ;; Searching / filtering (define (tagged tag) - "returns a list of all files with the given tag" + "returns a list of all ids with the given tag" (dict.get *tags* tag)) (define (get-by-title title) @@ -174,7 +174,9 @@ (define (template title body) `(html (head (title ,title)) (style ,*css*) - (body ,@body))) + (body + ;; TODO: nav bar + ,@body))) (define* (respond #:optional body #:key (status 200) @@ -206,20 +208,27 @@ (respond `((h1 "z") (ul - ,@(map - (lambda (id) - `(li (a (@ (href ,(fmt "/id/~a" id))) - ,(fmt "~a: ~a" - id (get-title (read-node id)))))) - (list-nodes)))))] + ,@(for (list-nodes) + (lambda (id) + `(li (a (@ (href ,(fmt "/id/~a" id))) + ,(fmt "~a: ~a" + id (get-title (read-node id))))))))))] [("id" id) (let ([node (read-node (string->id id))]) (respond `((pre ,node)) - #:title (fmt "z - ~a" (get-title node))))] - [("hacker") - (respond "Hello hacker!")] + #:title (fmt "z - ~a" (get-title node))))] + [("tag" tag) + (let ([ids (tagged tag)]) + `((ul ,@(for nodes + `(li (a (@ (href ,(mdt "/id~a" id))) + ,(fmt "~a: ~a" + id (get-title (read-node id)))))))))] [_ (respond "not found")])) +(define* (serve #:key (port 8080)) + (pr "z server") + (http.run-server routes 'http `(#:port ,port))) + ;; CLI (define (usage) @@ -227,7 +236,9 @@ usage: z [command] where 'command' is: <none> create new note - tagged [tag] list notes tagged with 'tag'")) + ls list all notes + tagged [tag] list notes tagged with 'tag' + web [port] start the webserver")) (define (main args) (match (rest args) @@ -247,7 +258,6 @@ where 'command' is: (pr id) (pr ": ") (pr title)))))] - [("web") (begin - (pr "z server") - (http.run-server routes))] + [("web") (serve)] + [("web" port) (serve #:port (string->number port))] [_ (usage)])) |