diff options
author | Ben Sima <ben@bsima.me> | 2020-05-09 22:31:30 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-05-09 22:31:30 -0700 |
commit | d4db97edda778fbf77cedc89f62184f412f18edf (patch) | |
tree | d67196c22139e9aa63a612b52b1a93b565e9c502 | |
parent | fd721e94532ba7f912d13706b3c03056345952e6 (diff) |
Add get-tags function
-rw-r--r-- | Alpha/String.scm | 7 | ||||
-rw-r--r-- | re.scm | 8 | ||||
-rw-r--r-- | z.scm | 26 |
3 files changed, 27 insertions, 14 deletions
diff --git a/Alpha/String.scm b/Alpha/String.scm index c7ad61f..4e32856 100644 --- a/Alpha/String.scm +++ b/Alpha/String.scm @@ -1,5 +1,10 @@ (define-module (Alpha String) - #:export (replace replace-char to-string str capitalize)) + #:export (replace replace-char to-string str capitalize split)) + +(define (split s c) + (if s + (string-split s c) + #f)) (define (replace-char s match repl) (let ((f (lambda (a b) @@ -1,7 +1,11 @@ #!r6rs (library (re (0)) - (export match) + (export match group) (import (rnrs base (6)) (ice-9 regex)) (define (match s pat) - (string-match pat s))) + (string-match pat s)) + (define (group m n) + (if m + (match:substring m n) + #f))) @@ -95,7 +95,7 @@ (define (cat-node id) (prn (read-node id))) -;; Indexing +;; Metadata (define (get-title id) (-> id @@ -103,17 +103,21 @@ (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-tags) - (define index-links) - ) +(define (get-tags id) + (-> id + read-node + (re.match "tags: ([^\n]*)") + (re.group 1) + (string.split #\space))) + +;; Indexing + +(define (index-titles) + (fold + (/. node ls (acons (get-title node) node ls)) + '() + (list-nodes))) |