posts have metadata
This commit is contained in:
parent
f1d0e122c2
commit
3694fa02a7
|
@ -142,6 +142,10 @@
|
||||||
(lambda (in out)
|
(lambda (in out)
|
||||||
(define prefs (prefs-load (hash-ref in "src/instance.rktd")))
|
(define prefs (prefs-load (hash-ref in "src/instance.rktd")))
|
||||||
(define instance-url (prefs-get prefs 'instance-url))
|
(define instance-url (prefs-get prefs 'instance-url))
|
||||||
|
(define src-meta-raw (read (hash-ref in post-src)))
|
||||||
|
(define src-meta
|
||||||
|
(for/hash ([x (in-list src-meta-raw)])
|
||||||
|
(values (first x) (second x))))
|
||||||
(define post-content (port->string (hash-ref in post-src)))
|
(define post-content (port->string (hash-ref in post-src)))
|
||||||
(define hashtags (mutable-set))
|
(define hashtags (mutable-set))
|
||||||
(define post-htmls (map (lambda (b)
|
(define post-htmls (map (lambda (b)
|
||||||
|
@ -149,7 +153,9 @@
|
||||||
(parse-markdown post-content)))
|
(parse-markdown post-content)))
|
||||||
(write-bytes
|
(write-bytes
|
||||||
(s-exp->fasl
|
(s-exp->fasl
|
||||||
(hash 'is-meow #t
|
(hash 'is-meow (hash-ref src-meta 'is-meow #t)
|
||||||
|
'title (hash-ref src-meta 'title "unknown")
|
||||||
|
'date (hash-ref src-meta 'date '(0 0 0))
|
||||||
'hashtags (set->list hashtags)
|
'hashtags (set->list hashtags)
|
||||||
'toc (toc post-htmls)
|
'toc (toc post-htmls)
|
||||||
'content post-htmls))
|
'content post-htmls))
|
||||||
|
|
|
@ -53,6 +53,8 @@
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(write-string "this section left intentionally blank")
|
(write-string "this section left intentionally blank")
|
||||||
(void)))
|
(void)))
|
||||||
|
(with-output-to-file "src/style.sass"
|
||||||
|
(lambda () (write-string "// styles go here :P") (void)))
|
||||||
(make-directory "src/posts")
|
(make-directory "src/posts")
|
||||||
|
|
||||||
(make-directory "public")
|
(make-directory "public")
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/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" "posts" 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))))
|
Loading…
Reference in New Issue