From 29e88e1dfe173a5cf86dc952a561cefd6ae866e0 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 11 May 2020 15:16:59 -0700 Subject: Add 'web port' argument, and some more page/templating --- z.scm | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/z.scm b/z.scm index ef7466e..1285126 100644 --- a/z.scm +++ b/z.scm @@ -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: 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)])) -- cgit v1.2.3