2020-05-14 20:39:57 +00:00
|
|
|
#!/usr/bin/env racket
|
|
|
|
#lang racket
|
|
|
|
; vim: ft=racket
|
|
|
|
|
|
|
|
(require racket/date)
|
|
|
|
|
|
|
|
(define (new-post name)
|
|
|
|
(define filename-part
|
|
|
|
(string-join
|
|
|
|
(regexp-match*
|
|
|
|
#px"([-]|\\p{L}|\\p{N})+"
|
|
|
|
(regexp-replace* #px"\\p{Z}+" (string-downcase name) "-"))
|
|
|
|
""))
|
|
|
|
(define now (current-date))
|
|
|
|
(define filename
|
|
|
|
(format "~a-~a-~a-~a.md" (date-year now)
|
|
|
|
(~r (date-month now) #:min-width 2 #:pad-string "0")
|
|
|
|
(~r (date-day now) #:min-width 2 #:pad-string "0") filename-part))
|
2020-05-14 20:42:01 +00:00
|
|
|
(define path (build-path "src" "drafts" filename))
|
2020-05-14 20:39:57 +00:00
|
|
|
(if (or (file-exists? path) (link-exists? path) (directory-exists? path))
|
|
|
|
(displayln "file already exists")
|
|
|
|
(with-output-to-file
|
|
|
|
path
|
|
|
|
(lambda ()
|
|
|
|
(pretty-write `((date (,(date-year now) ,(date-month now) ,(date-day now)))
|
|
|
|
(title ,name)
|
2020-07-23 05:02:00 +00:00
|
|
|
(summary "a new post on this blog")
|
2020-05-14 20:39:57 +00:00
|
|
|
(is-meow #t)))
|
2020-05-14 20:45:54 +00:00
|
|
|
(printf "\n# ~a\n\nHello world\n" name))))
|
2020-05-14 20:39:57 +00:00
|
|
|
(void))
|
|
|
|
|
|
|
|
(command-line
|
|
|
|
#:args (name . more-name)
|
|
|
|
(new-post (string-join (cons name more-name))))
|