summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--z.scm40
1 files 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:
<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)]))