summaryrefslogtreecommitdiff
path: root/z.scm
diff options
context:
space:
mode:
Diffstat (limited to 'z.scm')
-rw-r--r--z.scm55
1 files changed, 38 insertions, 17 deletions
diff --git a/z.scm b/z.scm
index 1285126..6d203fa 100644
--- a/z.scm
+++ b/z.scm
@@ -45,13 +45,6 @@
(define *zdir* (os.path.expanduser "~/test-z-wiki"))
-(define *about* "\
-# z is a zettelkasten tool
-
-- notes are stored as markdown with metadata
-- filenames serve as the note id's
-")
-
;; A node 'id' is a monotonically increasing number.
;; It can be represented as a string, in which case it is encoded in
@@ -145,6 +138,8 @@
(/. ids (cons id ids))))))))
(define (reindex)
+ (set! *titles* (dict.empty))
+ (set! *tags* (dict.empty))
(map index-node (list-nodes)))
;; Searching / filtering
@@ -171,11 +166,26 @@
(define *css* "body{max-width:650px;margin:40px auto;padding:0 10px;font:18px/1.5 -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";color:#444}h1,h2,h3{line-height:1.2}@media (prefers-color-scheme: dark){body{color:white;background:#444}a:link{color:#5bf}a:visited{color:#ccf}}")
+(define *navbar*
+ (let ((items (lambda ()
+ (unzip2
+ '(("index" "/")
+ #;("new" "/id/new")
+ ("tags" "/tag"))))))
+ `(nav
+ (ul
+ ,@(call-with-values items
+ (lambda (names paths)
+ (map (lambda (name path)
+ `(li (a (@ (href ,path)) ,name)))
+ names paths)))))))
+
(define (template title body)
`(html (head (title ,title))
(style ,*css*)
(body
- ;; TODO: nav bar
+ (h1 "z")
+ ,*navbar*
,@body)))
(define* (respond #:optional body #:key
@@ -206,27 +216,38 @@
(match (path-components req)
['()
(respond
- `((h1 "z")
- (ul
+ `((ul
,@(for (list-nodes)
(lambda (id)
- `(li (a (@ (href ,(fmt "/id/~a" id)))
+ `(li (a (@ (href ,(fmt "/node/~a" id)))
,(fmt "~a: ~a"
id (get-title (read-node id))))))))))]
- [("id" id)
+ [("node" id)
(let ([node (read-node (string->id id))])
(respond `((pre ,node))
#:title (fmt "z - ~a" (get-title node))))]
+ [("tag")
+ (let ((tags (dict.keys *tags*)))
+ (reindex)
+ (respond
+ `((ul ,@(for tags
+ (lambda [tag]
+ `(li (a (@ (href ,(fmt "/tag/~a" tag)))
+ ,(fmt "~a" tag)))))))))]
[("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
+ `((ul ,@(for ids
+ (lambda [id]
+ `(li (a (@ (href ,(fmt "/node/~a" id)))
+ ,(fmt "~a: ~a"
+ id
+ (get-title (read-node id)))))))))))]
[_ (respond "not found")]))
(define* (serve #:key (port 8080))
- (pr "z server")
+ (prn "z server")
+ (prn (fmt "port ~a" port))
(http.run-server routes 'http `(#:port ,port)))
;; CLI