hyde-blog added by ohwow on Thu May 19 10:00:03 2011

(use readline regex posix)

(define blog-path "/home/test/www/hyde-blog/")

(define editor (get-environment-variable "EDITOR"))
(define tmp-path (create-temporary-file))
(define title (gnu-readline "Title: " "> "))
(define current-date (current-seconds))

(define header `((layouts "blogpost.sxml" "default.sxml")
                 (title . ,title)
                 (tags )
                 (date . ,current-date)))

(define (clean-string str)
  (string-downcase (string-substitute* str '((" " . "_" ) ("!" . "1") ("," . ".")))))

(with-output-to-file tmp-path
  (λ ()
    (write header)
    (newline)))

(system (string-append editor " " tmp-path))

(printf "Procceed with posting \"~a\"? [y/n]: " title)
(if (equal? #\y (char-downcase (read-char)))
    (let ((post-path (clean-string title)))
      (display (string-append "cp "
                              tmp-path
                              " \"" blog-path
                              "src/posts/" post-path ".md\""))
      (newline)
      (system (string-append "cp "
                             tmp-path
                             " \"" blog-path
                             "src/posts/" post-path ".md\""))
      (change-directory blog-path)
      (system "hyde"))
    (printf "Okay\n"))