|
@@ -11,38 +11,14 @@
|
11
|
11
|
(format :initform nil :initarg :format :accessor post-format)
|
12
|
12
|
(content :initform nil :initarg :content :accessor post-content)))
|
13
|
13
|
|
14
|
|
-(defmethod render ((content post) &key prev next)
|
|
14
|
+(defmethod render ((object post) &key prev next)
|
15
|
15
|
(funcall (theme-fn 'post) (list :config *config*
|
16
|
|
- :post content
|
|
16
|
+ :post object
|
17
|
17
|
:prev prev
|
18
|
18
|
:next next)))
|
19
|
19
|
|
20
|
|
-(defun load-posts ()
|
21
|
|
- "Read the stored .post files from the repo."
|
22
|
|
- (clrhash *posts*)
|
23
|
|
- (do-files (file (repo *config*) "post")
|
24
|
|
- (with-open-file (in file)
|
25
|
|
- (let ((post (read-post in)))
|
26
|
|
- (if (gethash (post-slug post) *posts*)
|
27
|
|
- (error "There is already an existing post with the slug ~a."
|
28
|
|
- (post-slug post))
|
29
|
|
- (setf (gethash (post-slug post) *posts*) post))))))
|
30
|
|
-
|
31
|
|
-(defun render-posts ()
|
32
|
|
- "Iterate through the files in the repo to render+write the posts out to disk."
|
33
|
|
- (loop for (prev post next) on (append '(nil) (sort (hash-table-values *posts*)
|
34
|
|
- #'string< :key #'post-date))
|
35
|
|
- while post do (render-page post nil :prev prev :next next)))
|
36
|
|
-
|
37
|
|
-(defgeneric render-content (text format)
|
38
|
|
- (:documentation "Compile TEXT from the given FORMAT to HTML for display.")
|
39
|
|
- (:method (text (format (eql :html)))
|
40
|
|
- text))
|
41
|
|
-
|
42
|
|
-(defmethod render-content (text (format (eql :md)))
|
43
|
|
- (let ((3bmd-code-blocks:*code-blocks* t))
|
44
|
|
- (with-output-to-string (str)
|
45
|
|
- (3bmd:parse-string-and-print-to-stream text str))))
|
|
20
|
+(defmethod page-path ((post post))
|
|
21
|
+ (rel-path (staging *config*) "posts/~a.html" (post-slug post)))
|
46
|
22
|
|
47
|
23
|
(defun read-post (in)
|
48
|
24
|
"Make a POST instance based on the data from the stream IN."
|
|
@@ -51,6 +27,8 @@
|
51
|
27
|
(error "The provided file lacks the expected header.")))
|
52
|
28
|
(parse-field (str)
|
53
|
29
|
(nth-value 1 (cl-ppcre:scan-to-strings "[a-zA-Z]+: (.*)" str)))
|
|
30
|
+ (field-name (line)
|
|
31
|
+ (subseq line 0 (position #\: line)))
|
54
|
32
|
(read-tags (str)
|
55
|
33
|
(mapcar #'string-downcase (cl-ppcre:split ", " str)))
|
56
|
34
|
(slurp-remainder ()
|
|
@@ -58,11 +36,9 @@
|
58
|
36
|
(read-sequence seq in)
|
59
|
37
|
(remove #\Nul seq))))
|
60
|
38
|
(check-header)
|
61
|
|
- (let ((args (loop for field in '("title" "tags" "date" "format")
|
62
|
|
- for line = (read-line in nil)
|
63
|
|
- appending (list (make-keyword (string-upcase field))
|
|
39
|
+ (let ((args (loop for line = (read-line in nil) until (string= line ";;;;;")
|
|
40
|
+ appending (list (make-keyword (string-upcase (field-name line)))
|
64
|
41
|
(aref (parse-field line) 0)))))
|
65
|
|
- (check-header)
|
66
|
42
|
(setf (getf args :tags) (read-tags (getf args :tags))
|
67
|
43
|
(getf args :format) (make-keyword (string-upcase (getf args :format))))
|
68
|
44
|
(apply 'make-instance 'post
|
|
@@ -70,6 +46,24 @@
|
70
|
46
|
(getf args :format))
|
71
|
47
|
:slug (slugify (getf args :title))))))))
|
72
|
48
|
|
|
49
|
+(defun load-posts ()
|
|
50
|
+ "Read the stored .post files from the repo."
|
|
51
|
+ (clrhash *posts*)
|
|
52
|
+ (do-files (file (repo *config*) "post")
|
|
53
|
+ (with-open-file (in file)
|
|
54
|
+ (let ((post (read-post in)))
|
|
55
|
+ (if (gethash (post-slug post) *posts*)
|
|
56
|
+ (error "There is already an existing post with the slug ~a."
|
|
57
|
+ (post-slug post))
|
|
58
|
+ (setf (gethash (post-slug post) *posts*) post))))))
|
|
59
|
+
|
|
60
|
+(defun render-posts ()
|
|
61
|
+ "Iterate through the files in the repo to render+write the posts out to disk."
|
|
62
|
+ (loop for (prev post next) on (append '(nil) (sort (hash-table-values *posts*)
|
|
63
|
+ #'string< :key #'post-date))
|
|
64
|
+ while post do (write-page (page-path post)
|
|
65
|
+ (render-page post nil :prev prev :next next))))
|
|
66
|
+
|
73
|
67
|
(defun slug-char-p (char)
|
74
|
68
|
"Determine if CHAR is a valid slug (i.e. URL) character."
|
75
|
69
|
(or (char<= #\0 char #\9)
|