Only read a line in once, make posts, not blogs.

This commit is contained in:
Brit Butler 2012-08-21 16:37:18 -04:00
parent 01d6b97974
commit 72e631e8a4

View file

@ -38,21 +38,17 @@
(unless (string= (read-line in) ";;;;;")
(error "The provided file lacks the expected header.")))
(parse-field (str)
(nth-value 1 (cl-ppcre:scan-to-strings "[a-zA-Z]+: (.*)" str)))
(slurp-remainder ()
(read-sequence (make-string (- (file-length in)
(file-position in))
:element-type 'character) in)))
(nth-value 1 (cl-ppcre:scan-to-strings "[a-zA-Z]+: (.*)" str))))
(check-header)
(let ((args (loop for field in '("title" "tags" "date" "format")
for line = (read-line in nil)
appending (list (make-keyword field)
(aref (parse-field (read-line in)) 0)))))
(aref (parse-field line) 0)))))
(check-header)
(setf (getf args :tags) (cl-ppcre:split ", " (getf args :tags))
(getf args :format) (make-keyword (getf args :format)))
(apply 'make-instance 'blog
(append args (list :content (slurp-remainder)
(apply 'make-instance 'post
(append args (list :content (read-line in nil)
:slug (slugify (getf args :title))))))))
(defun write-post (slug post)