chomp/scripts/new-post

34 lines
1.0 KiB
Racket
Executable File

#!/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))
(define path (build-path "src" "drafts" filename))
(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)
(is-meow #t)))
(write-string (format "\n# ~a\n\nHello world\n" name)))))
(void))
(command-line
#:args (name . more-name)
(new-post (string-join (cons name more-name))))