diff options
author | Ben Sima <ben@bsima.me> | 2020-05-11 18:45:31 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-05-11 18:45:31 -0700 |
commit | df1c3f1f62769e31605d6635f465b1d03d38b6af (patch) | |
tree | bcf51779e86178427d9286370a128d5508474669 | |
parent | 29e88e1dfe173a5cf86dc952a561cefd6ae866e0 (diff) |
Add 'tag' index page and navbar
-rw-r--r-- | z.scm | 55 |
1 files changed, 38 insertions, 17 deletions
@@ -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 |