|
@ -5,6 +5,7 @@ |
|
|
(require net/url) |
|
|
(require net/url) |
|
|
(require racket/string) |
|
|
(require racket/string) |
|
|
(require readline/readline) |
|
|
(require readline/readline) |
|
|
|
|
|
(require "categorize.rkt") |
|
|
|
|
|
|
|
|
(define (create-config path ex) |
|
|
(define (create-config path ex) |
|
|
(let ([password (readline "Your wordpress password? ")] |
|
|
(let ([password (readline "Your wordpress password? ")] |
|
@ -65,6 +66,9 @@ |
|
|
; The current configuration |
|
|
; The current configuration |
|
|
(define your-config (new-config "/home/wes/.config/gitblog.conf")) |
|
|
(define your-config (new-config "/home/wes/.config/gitblog.conf")) |
|
|
|
|
|
|
|
|
|
|
|
(define password (make-parameter #f)) |
|
|
|
|
|
(define username (make-parameter #f)) |
|
|
|
|
|
|
|
|
; Run a command and get the string written to stdout |
|
|
; Run a command and get the string written to stdout |
|
|
(define (system-result command) |
|
|
(define (system-result command) |
|
|
(match |
|
|
(match |
|
@ -104,12 +108,6 @@ |
|
|
(name ,(car member)) |
|
|
(name ,(car member)) |
|
|
,(cadr member))))) |
|
|
,(cadr member))))) |
|
|
|
|
|
|
|
|
(define password |
|
|
|
|
|
(xstring (your-config 'password))) |
|
|
|
|
|
|
|
|
|
|
|
(define username |
|
|
|
|
|
(xstring (your-config 'username))) |
|
|
|
|
|
|
|
|
|
|
|
; Puts the tags and categories into a terms_names struct |
|
|
; Puts the tags and categories into a terms_names struct |
|
|
(define (terms-names tags categories) |
|
|
(define (terms-names tags categories) |
|
|
(xstruct |
|
|
(xstruct |
|
@ -129,8 +127,8 @@ |
|
|
(method-call 'wp.newPost |
|
|
(method-call 'wp.newPost |
|
|
(list |
|
|
(list |
|
|
(xint 1) |
|
|
(xint 1) |
|
|
username |
|
|
(username) |
|
|
password |
|
|
(password) |
|
|
(xstruct |
|
|
(xstruct |
|
|
`(("post_title" |
|
|
`(("post_title" |
|
|
,(xstring post-title)) |
|
|
,(xstring post-title)) |
|
@ -149,8 +147,8 @@ |
|
|
(method-call 'wp.deletePost |
|
|
(method-call 'wp.deletePost |
|
|
(list |
|
|
(list |
|
|
(xint 1) |
|
|
(xint 1) |
|
|
username |
|
|
(username) |
|
|
password |
|
|
(password) |
|
|
(xint post-id)))) |
|
|
(xint post-id)))) |
|
|
|
|
|
|
|
|
; Updates an existing post |
|
|
; Updates an existing post |
|
@ -160,8 +158,8 @@ |
|
|
(method-call 'wp.editPost |
|
|
(method-call 'wp.editPost |
|
|
(list |
|
|
(list |
|
|
(xint 1) |
|
|
(xint 1) |
|
|
username |
|
|
(username) |
|
|
password |
|
|
(password) |
|
|
(xint post-id) |
|
|
(xint post-id) |
|
|
(xstruct |
|
|
(xstruct |
|
|
`(("post_title" |
|
|
`(("post_title" |
|
@ -212,17 +210,17 @@ |
|
|
"\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 categories text) |
|
|
(let ([lines (string-split text "\n")]) |
|
|
(let ([lines (string-split text "\n")]) |
|
|
(values |
|
|
(values |
|
|
(car lines) |
|
|
(car lines) |
|
|
(string-join |
|
|
(string-join |
|
|
(cdr lines) |
|
|
(cdr lines) |
|
|
"\n") |
|
|
"\n") |
|
|
'("test" "firstpost") '("Introduction" "Tests")))) |
|
|
'("test" "firstpost") categories))) |
|
|
|
|
|
|
|
|
; Writes a new post and returns its post id |
|
|
; Writes a new post and returns its post id |
|
|
(define (handle-post status post post-id) |
|
|
(define (handle-post categories status post post-id) |
|
|
(match status |
|
|
(match status |
|
|
|
|
|
|
|
|
[(? (lambda (x) |
|
|
[(? (lambda (x) |
|
@ -232,6 +230,7 @@ |
|
|
(call-with-values |
|
|
(call-with-values |
|
|
(lambda () |
|
|
(lambda () |
|
|
(parse-post |
|
|
(parse-post |
|
|
|
|
|
categories |
|
|
(port->string |
|
|
(port->string |
|
|
(open-input-file post)))) |
|
|
(open-input-file post)))) |
|
|
(curry write-post post-id))] |
|
|
(curry write-post post-id))] |
|
@ -309,10 +308,14 @@ |
|
|
|
|
|
|
|
|
; 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) |
|
|
|
|
|
(parameterize |
|
|
|
|
|
([blog-location (your-config 'blog-location)]) |
|
|
(for ([post-file (get-files)]) |
|
|
(for ([post-file (get-files)]) |
|
|
|
|
|
|
|
|
(let ([post-status (car post-file)] |
|
|
(let* ([post-status (car post-file)] |
|
|
[post (cadr post-file)]) |
|
|
[post (cadr post-file)] |
|
|
|
|
|
[categories (get-categories post)]) |
|
|
|
|
|
(displayln categories) |
|
|
|
|
|
|
|
|
(match (git-href post #f) |
|
|
(match (git-href post #f) |
|
|
|
|
|
|
|
@ -321,12 +324,12 @@ |
|
|
; 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-status post #f))] |
|
|
(git-set! post (handle-post categories 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-status post post-id))])))) |
|
|
(handle-post categories post-status post post-id))]))))) |
|
|
|
|
|
|
|
|
(provide |
|
|
(provide |
|
|
git-href |
|
|
git-href |
|
@ -335,4 +338,7 @@ |
|
|
new-config |
|
|
new-config |
|
|
get-commits |
|
|
get-commits |
|
|
current-commits |
|
|
current-commits |
|
|
your-config) |
|
|
your-config |
|
|
|
|
|
password |
|
|
|
|
|
username |
|
|
|
|
|
xstring) |