summaryrefslogtreecommitdiff
path: root/z.scm
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-05-09 22:18:17 -0700
committerBen Sima <ben@bsima.me>2020-05-09 22:18:17 -0700
commitfd721e94532ba7f912d13706b3c03056345952e6 (patch)
tree7c273db16e0e8dc4de7f1702e50e2e368bbd18b5 /z.scm
parent1542c85458dcd58bb6d40f1f8d3917f80298ddd2 (diff)
Index titles
Also don't overwrite srfi-1 stuff, and added an re module.
Diffstat (limited to 'z.scm')
-rw-r--r--z.scm36
1 files changed, 29 insertions, 7 deletions
diff --git a/z.scm b/z.scm
index 0267a7d..6e8972a 100644
--- a/z.scm
+++ b/z.scm
@@ -1,5 +1,8 @@
(import (Alpha Core))
-(import (prefix (Alpha String) string/))
+(import (prefix (Alpha String) string.))
+(import (srfi srfi-1))
+(import (only (srfi srfi-19) date->string current-date))
+(import (prefix (re) re.))
;; general functions
@@ -9,7 +12,7 @@
(define (os.path.expanduser path)
(let ([home (getenv "HOME")])
- (string/replace path "~" home)))
+ (string.replace path "~" home)))
(import (only (srfi srfi-1) remove))
(define (rm ls item)
@@ -49,8 +52,8 @@
(define (path->id fname)
"Given a path, parse out the node id."
(-> fname
- (string/replace ".md" "")
- (string/replace *zdir* "")
+ (string.replace ".md" "")
+ (string.replace *zdir* "")
(string->id)))
(define (id->path id)
@@ -86,12 +89,31 @@
(format file "tags:\n")
(display "---\n" file))))
+(define (read-node id)
+ (readlines (id->path id)))
+
(define (cat-node id)
- (prn (readlines (id->path id))))
+ (prn (read-node id)))
;; Indexing
+(define (get-title id)
+ (-> id
+ read-node
+ (re.match "title: ([^\n]*)")
+ (match:substring 1)))
+
+(define (index-titles)
+ (fold
+ (lambda (node ls) (acons (get-title node) node ls))
+ '()
+ (list-nodes)))
+
+(define (get-by-title title)
+ (let ([index (index-titles)])
+ (assoc title index)))
+
(comment
- (define index-titles)
+ (define index-tags)
(define index-links)
- (define index-tags))
+ )