-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcycle-dev.lisp
53 lines (44 loc) · 2.31 KB
/
cycle-dev.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;;;; cycle-dev.lisp
(require "asdf")
(defpackage :cycle-dev
(:use
:cl
:cycle))
(in-package :cycle-dev)
(when (uiop:file-exists-p "BLOG")
(defvar *db* (sqlite:connect "BLOG")))
(defun gen-md ()
"One-off command to turn html files into md files via pandco process."
(let* ((files (uiop:directory-files "posts/" "*.html"))
(formatted (mapcar (lambda(file) `(,file . ,(cycle:file-basename file))) files)))
(dolist (file formatted)
(uiop:launch-program (concatenate 'string "/usr/local/bin/pandoc "
(uiop:unix-namestring (car file))
" -t gfm --wrap=none -o posts/"
(cdr file)
".md")))))
(defun write-posts-to-file ()
"This grabs the raw data out of the db and writes it to HTML files."
(let ((posts (sqlite:execute-to-list *db* "select id,slug,title,pub_date,mod_date,excerpt,content from posts")))
(dolist (post posts)
(cycle:write-file (car (last post)) (concatenate 'string "posts/" (second post) ".html")))))
(defun write-data-to-file()
(let ((posts (sqlite:execute-to-list *db* "select id,slug,title,pub_date,mod_date,excerpt from posts")))
(dolist (post posts)
(cycle:write-file (data-to-json post) (concatenate 'string "posts/" (second post) ".json")))))
(defun data-to-json(post)
(let ((json (json:encode-json-to-string `(
("id" . ,(first post))
("slug" . ,(second post))
("title" . ,(third post))
("published" . ,(coerce-tz (fourth post)))
("modified" . ,(coerce-tz (fifth post)))
("excerpt" . ,(string-trim " " (sixth post)))))))
json))
(defun coerce-tz(date)
(let* ((no-zone (substitute #\T #\Space date))
(digit (parse-integer (car (cycle:split-string (car (cdr (cycle:split-string date " "))) ":"))))
(parsed-hour (local-time:timestamp-hour (local-time:parse-timestring (concatenate 'string no-zone "-04:00")))))
(if (eq parsed-hour digit)
(concatenate 'string no-zone "-04:00")
(concatenate 'string no-zone "-05:00"))))