From 3694fa02a7f831d1aed57952029a0925b431e04a Mon Sep 17 00:00:00 2001 From: haskal Date: Thu, 14 May 2020 16:39:57 -0400 Subject: [PATCH] posts have metadata --- private/rules.rkt | 8 +++++++- scripts/init | 2 ++ scripts/new-post | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100755 scripts/new-post diff --git a/private/rules.rkt b/private/rules.rkt index 6364ec2..0935512 100644 --- a/private/rules.rkt +++ b/private/rules.rkt @@ -142,6 +142,10 @@ (lambda (in out) (define prefs (prefs-load (hash-ref in "src/instance.rktd"))) (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 hashtags (mutable-set)) (define post-htmls (map (lambda (b) @@ -149,7 +153,9 @@ (parse-markdown post-content))) (write-bytes (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) 'toc (toc post-htmls) 'content post-htmls)) diff --git a/scripts/init b/scripts/init index 1b92097..70c7996 100755 --- a/scripts/init +++ b/scripts/init @@ -53,6 +53,8 @@ (lambda () (write-string "this section left intentionally blank") (void))) +(with-output-to-file "src/style.sass" + (lambda () (write-string "// styles go here :P") (void))) (make-directory "src/posts") (make-directory "public") diff --git a/scripts/new-post b/scripts/new-post new file mode 100755 index 0000000..bb886da --- /dev/null +++ b/scripts/new-post @@ -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))))