diff options
-rw-r--r-- | z.scm | 47 |
1 files changed, 34 insertions, 13 deletions
@@ -1,18 +1,17 @@ (import (Alpha Core)) -(import (Alpha String)) -(import (only (Alpha String) replace)) -(import (only (ice-9 ftw) scandir)) -(import (only (srfi srfi-1) remove)) +(import (prefix (Alpha String) string/)) ;; general functions +(import (only (ice-9 ftw) scandir)) (define (os.listdir path) (scandir path)) (define (os.path.expanduser path) (let ([home (getenv "HOME")]) - (replace path "~" home))) + (string/replace path "~" home))) +(import (only (srfi srfi-1) remove)) (define (rm ls item) (remove (/. x (eq? x item)) ls)) @@ -23,6 +22,12 @@ [else (set.difference (rest s1) s2)])) +(import (only (ice-9 rdelim) read-delimited)) +(define (readlines fname) + (call-with-input-file fname + (lambda [p] + (read-delimited "" p 'concat)))) + ;; z program (define *zdir* (os.path.expanduser "~/test-z-wiki")) @@ -44,8 +49,8 @@ (define (path->id fname) "Given a path, parse out the node id." (-> fname - (replace ".md" "") - (replace *zdir* "") + (string/replace ".md" "") + (string/replace *zdir* "") (string->id))) (define (id->path id) @@ -56,21 +61,37 @@ ;; Manipulating nodes -(define (list-nodes dir) +(define (list-nodes* dir) (->> dir (os.listdir) ;; remove '.' and '..' ((/. s (set.difference s '("." "..")))) (map path->id))) +(define (list-nodes) + (list-nodes* *zdir*)) + (define (latest-node ls) (if (eq? ls '()) 0 (apply max ls))) (define (make-node title) - (let ([id (inc (-> *zdir* list-nodes latest-node))]) - (call-with-output-file (id->path id) - (fn [file] - (format file "title: ~a" title) - (newline file))))) + (call-with-output-file + (-> (list-nodes) latest-node inc id->path) + (fn [file] + (format file "title: ~a\n" title) + (format file "created: ~a\n" + (date->string (current-date) "~Y.~m.~d..~H.~M")) + (format file "tags:\n") + (display "---\n" file)))) + +(define (cat-node id) + (prn (readlines (id->path id)))) + +;; Indexing + +(comment + (define index-titles) + (define index-links) + (define index-tags)) |