|
@@ -36,6 +36,11 @@
|
36
|
36
|
(date :initform nil :initarg :date :accessor content-date)
|
37
|
37
|
(text :initform nil :initarg :text :accessor content-text)))
|
38
|
38
|
|
|
39
|
+(defmethod initialize-instance :after ((object content) &key)
|
|
40
|
+ (with-accessors ((tags content-tags)) object
|
|
41
|
+ (when (stringp tags)
|
|
42
|
+ (setf tags (mapcar #'make-tag (cl-ppcre:split "," tags))))))
|
|
43
|
+
|
39
|
44
|
(defun read-content (file)
|
40
|
45
|
"Returns a plist of metadata from FILE with :text holding the content as a string."
|
41
|
46
|
(flet ((slurp-remainder (stream)
|
|
@@ -46,9 +51,7 @@
|
46
|
51
|
(parse-field (str)
|
47
|
52
|
(nth-value 1 (cl-ppcre:scan-to-strings "[a-zA-Z]+: (.*)" str)))
|
48
|
53
|
(field-name (line)
|
49
|
|
- (make-keyword (string-upcase (subseq line 0 (position #\: line)))))
|
50
|
|
- (read-tags (str)
|
51
|
|
- (mapcar #'make-tag (cl-ppcre:split "," str))))
|
|
54
|
+ (make-keyword (string-upcase (subseq line 0 (position #\: line))))))
|
52
|
55
|
(with-open-file (in file :external-format '(:utf-8))
|
53
|
56
|
(unless (string= (read-line in) (separator *config*))
|
54
|
57
|
(error "The provided file lacks the expected header."))
|
|
@@ -57,7 +60,6 @@
|
57
|
60
|
appending (list (field-name line)
|
58
|
61
|
(aref (parse-field line) 0))))
|
59
|
62
|
(content (slurp-remainder in)))
|
60
|
|
- (setf (getf meta :tags) (read-tags (getf meta :tags)))
|
61
|
63
|
(append meta (list :text content))))))
|
62
|
64
|
|
63
|
65
|
;; Helper Functions
|