|
@ -45,7 +45,6 @@ |
|
|
(match (map string-trim |
|
|
(match (map string-trim |
|
|
(string-split line "=")) |
|
|
(string-split line "=")) |
|
|
[(list key val) |
|
|
[(list key val) |
|
|
(displayln (format "~a - ~a" key val)) |
|
|
|
|
|
(cond |
|
|
(cond |
|
|
[(valid-key? key) (hash-set! config (string->symbol key) val)] |
|
|
[(valid-key? key) (hash-set! config (string->symbol key) val)] |
|
|
[else |
|
|
[else |
|
@ -137,6 +136,14 @@ |
|
|
("terms_names" |
|
|
("terms_names" |
|
|
,terms_names)))))) |
|
|
,terms_names)))))) |
|
|
|
|
|
|
|
|
|
|
|
(define (delete-post post-id) |
|
|
|
|
|
(method-call 'wp.deletePost |
|
|
|
|
|
(list |
|
|
|
|
|
(xint 1) |
|
|
|
|
|
username |
|
|
|
|
|
password |
|
|
|
|
|
(xint post-id)))) |
|
|
|
|
|
|
|
|
; Updates an existing post |
|
|
; Updates an existing post |
|
|
(define (edit-post post-title |
|
|
(define (edit-post post-title |
|
|
post-content |
|
|
post-content |
|
@ -172,14 +179,28 @@ |
|
|
[(not post-id) (new-post title content (terms-names tags categories))] |
|
|
[(not post-id) (new-post title content (terms-names tags categories))] |
|
|
[else (edit-post title content post-id)]))))))) |
|
|
[else (edit-post title content post-id)]))))))) |
|
|
|
|
|
|
|
|
|
|
|
; Deletes a post |
|
|
|
|
|
(define (rm-post post-id) |
|
|
|
|
|
(port->string |
|
|
|
|
|
(post-pure-port |
|
|
|
|
|
(string->url (your-config 'url)) |
|
|
|
|
|
(string->bytes/utf-8 |
|
|
|
|
|
(xexpr->string |
|
|
|
|
|
(delete-post post-id)))))) |
|
|
|
|
|
|
|
|
; Returns a list of all modified post files in this commit |
|
|
; Returns a list of all modified post files in this commit |
|
|
(define (get-files) |
|
|
(define (get-files) |
|
|
|
|
|
(map |
|
|
|
|
|
(lambda (file) |
|
|
|
|
|
(string-split |
|
|
|
|
|
file |
|
|
|
|
|
":")) |
|
|
(string-split |
|
|
(string-split |
|
|
(with-output-to-string |
|
|
(with-output-to-string |
|
|
(lambda () |
|
|
(lambda () |
|
|
(system |
|
|
(system |
|
|
"git status --short | grep -E '^(A|M)' | awk '{ print $2 }' | grep -E '\\.post$'"))) |
|
|
"git status --short | grep -E '^(A|M|D)' | awk '{ printf \"%s:%s\\n\",$1,$2 }' | grep -E '\\.post$'"))) |
|
|
"\n")) |
|
|
"\n"))) |
|
|
|
|
|
|
|
|
; Parses a post file and returns the components |
|
|
; Parses a post file and returns the components |
|
|
(define (parse-post text) |
|
|
(define (parse-post text) |
|
@ -192,13 +213,16 @@ |
|
|
'("test" "firstpost") '("Introduction" "Tests")))) |
|
|
'("test" "firstpost") '("Introduction" "Tests")))) |
|
|
|
|
|
|
|
|
; Writes a new post and returns its post id |
|
|
; Writes a new post and returns its post id |
|
|
(define (handle-post post post-id) |
|
|
(define (handle-post status post post-id) |
|
|
|
|
|
(match status |
|
|
|
|
|
[(? (lambda (x) (ormap (curry equal? x) (list "A" "M")))) |
|
|
(call-with-values |
|
|
(call-with-values |
|
|
(lambda () |
|
|
(lambda () |
|
|
(parse-post |
|
|
(parse-post |
|
|
(port->string |
|
|
(port->string |
|
|
(open-input-file post)))) |
|
|
(open-input-file post)))) |
|
|
(curry write-post post-id))) |
|
|
(curry write-post post-id))] |
|
|
|
|
|
["D" (rm-post post-id)])) |
|
|
|
|
|
|
|
|
; Get a list of all commit refs |
|
|
; Get a list of all commit refs |
|
|
(define (get-commits) |
|
|
(define (get-commits) |
|
@ -264,17 +288,19 @@ |
|
|
|
|
|
|
|
|
; Run when a commit of one or more posts occurs |
|
|
; Run when a commit of one or more posts occurs |
|
|
(define (commit-posts) |
|
|
(define (commit-posts) |
|
|
(for ([post (get-files)]) |
|
|
(for ([post-file (get-files)]) |
|
|
|
|
|
(let ([post-status (car post-file)] |
|
|
|
|
|
[post (cadr post-file)]) |
|
|
(match (git-href post #f) |
|
|
(match (git-href post #f) |
|
|
[#f |
|
|
[#f |
|
|
(when (empty? (current-commits)) |
|
|
(when (empty? (current-commits)) |
|
|
; Add a first commit if there are none so it can store the note properly! |
|
|
; Add a first commit if there are none so it can store the note properly! |
|
|
(system "git commit -n --allow-empty -m \"bootstrap blog\"")) |
|
|
(system "git commit -n --allow-empty -m \"bootstrap blog\"")) |
|
|
(git-set! post (handle-post post #f))] |
|
|
(git-set! post (handle-post post-status post #f))] |
|
|
[commit-id |
|
|
[commit-id |
|
|
(let ([post-id (commit->post-id post commit-id)]) |
|
|
(let ([post-id (commit->post-id post commit-id)]) |
|
|
(git-set! post post-id) |
|
|
(git-set! post post-id) |
|
|
(handle-post post post-id))]))) |
|
|
(handle-post post-status post post-id))])))) |
|
|
|
|
|
|
|
|
(provide |
|
|
(provide |
|
|
git-href |
|
|
git-href |
|
@ -282,4 +308,5 @@ |
|
|
commit-posts |
|
|
commit-posts |
|
|
new-config |
|
|
new-config |
|
|
get-commits |
|
|
get-commits |
|
|
current-commits) |
|
|
current-commits |
|
|
|
|
|
your-config) |
|
|