From f318d31174d09fd5a58da728e4d9f3da00dd80d2 Mon Sep 17 00:00:00 2001 From: "wjak56@gmail.com" Date: Mon, 10 Aug 2015 14:08:31 -0400 Subject: [PATCH] Categories and stuff --- api.rkt | 40 +++++++++++++++++++++++++++++++++------- categorize.rkt | 11 +++++++++++ rm.rkt | 4 ---- 3 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 categorize.rkt delete mode 100644 rm.rkt diff --git a/api.rkt b/api.rkt index 199a1ca..48834cc 100644 --- a/api.rkt +++ b/api.rkt @@ -35,21 +35,28 @@ (define (new-config path) (with-handlers ([exn:fail:filesystem:errno? (curry create-config path)]) + (let* ([config-file (open-input-file path)] [lines (string-split (port->string config-file) "\n")] [config (make-hash)]) + (for ([line lines] #:unless (string=? line "")) + (match (map string-trim (string-split line "=")) [(list key val) (cond - [(valid-key? key) (hash-set! config (string->symbol key) val)] + [(valid-key? key) + (hash-set! config + (string->symbol key) + val)] [else (error (format "Invalid configuration line: ~a" val))])])) + (curry hash-ref config)))) ; The current list of commits (as a dynamically scoped name) @@ -63,8 +70,10 @@ (match (process command) [(list out in pid errport _) + (let ([result (port->string out)] [err-result (port->string out)]) + (close-input-port out) (close-output-port in) (close-input-port errport) @@ -215,14 +224,22 @@ ; Writes a new post and returns its post id (define (handle-post status post post-id) (match status - [(? (lambda (x) (ormap (curry equal? x) (list "A" "M")))) + + [(? (lambda (x) + (ormap + (curry equal? x) + (list "A" "M")))) (call-with-values (lambda () (parse-post (port->string (open-input-file post)))) (curry write-post post-id))] - ["D" (rm-post post-id)])) + + ["D" (rm-post post-id)] + + [m (error + (format "Unimplemented mode ~a" m))])) ; Get a list of all commit refs (define (get-commits) @@ -248,6 +265,7 @@ post-name commit-ref)) [#f ""] + [str str]))]) result)) @@ -265,7 +283,9 @@ ["" #f] [result #t]))) (current-commits)) + [(list-rest commit-id _) commit-id] + [_ (cond [(eq? def-val default) @@ -274,6 +294,7 @@ (format "git-href: no value found for key\n\t~a" post-name) (current-continuation-marks)))] + [else default])])))) ; Add or refresh a key associated with that value @@ -289,14 +310,19 @@ ; Run when a commit of one or more posts occurs (define (commit-posts) (for ([post-file (get-files)]) - (let ([post-status (car post-file)] + + (let ([post-status (car post-file)] [post (cadr post-file)]) - (match (git-href post #f) - [#f + + (match (git-href post #f) + + [#f (when (empty? (current-commits)) ; Add a first commit if there are none so it can store the note properly! (system "git commit -n --allow-empty -m \"bootstrap blog\"")) + (git-set! post (handle-post post-status post #f))] + [commit-id (let ([post-id (commit->post-id post commit-id)]) (git-set! post post-id) @@ -309,4 +335,4 @@ new-config get-commits current-commits - your-config) + your-config) \ No newline at end of file diff --git a/categorize.rkt b/categorize.rkt new file mode 100644 index 0000000..d120e31 --- /dev/null +++ b/categorize.rkt @@ -0,0 +1,11 @@ +#lang racket + +(define/contract (categorize path-string) + (-> absolute-path? any) + (let-values ([(upper bottom not-root?) + (split-path path-string)]) + (cond + [(not upper) '()] + [else + (cons (path->string bottom) + (categorize (path->string upper)))]))) \ No newline at end of file diff --git a/rm.rkt b/rm.rkt deleted file mode 100644 index 306789d..0000000 --- a/rm.rkt +++ /dev/null @@ -1,4 +0,0 @@ -#! /usr/bin/racket -#lang racket - -