From 0d0f7b564b84970eaf2c93f46037a370a9c2f301 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Mon, 20 Aug 2012 20:36:57 -0400 Subject: [PATCH] Sketch of READ-POST. --- TODO | 3 +-- plugins/import.lisp | 2 +- src/posts.lisp | 28 +++++++++++++++++++++++----- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/TODO b/TODO index 782778f..01fc464 100644 --- a/TODO +++ b/TODO @@ -13,8 +13,7 @@ Plugins? Injection support for HEAD and BODY. What about predicate-based injecti How is it served? Hunchentoot, Lighttpd, S3, whomever! TODO: -; implement read-post -; fix plugins: s3, wordpress +; fix plugins: s3 ; doc themes and plugins ; implement plugins: atom, markdown, pygment/highlighting ; actually start using this for redlinernotes.com? Move over May-2007 to present. diff --git a/plugins/import.lisp b/plugins/import.lisp index 26827c5..ed1830e 100644 --- a/plugins/import.lisp +++ b/plugins/import.lisp @@ -41,7 +41,7 @@ (format out "title: ~A~%" title) (format out "tags: ~A~%" (format nil "~{~A, ~}" tags)) (format out "date: ~A~%" date) - (format out "type: html~%") ; post format: html, md, rst, etc + (format out "format: html~%") ; post format: html, md, rst, etc (format out ";;;;;~%") (format out "~A~%" (post-content post)))) diff --git a/src/posts.lisp b/src/posts.lisp index a71ca12..e580fce 100644 --- a/src/posts.lisp +++ b/src/posts.lisp @@ -9,8 +9,7 @@ (tags :initform nil :initarg :tags :accessor post-tags) (date :initform nil :initarg :date :accessor post-date) (format :initform nil :initarg :format :accessor post-format) - (content :initform nil :initarg :content :accessor post-content) - (aliases :initform nil :initarg :aliases :accessor post-aliases))) + (content :initform nil :initarg :content :accessor post-content))) (defun render-posts () "Iterate through the files in the repo to render+write the posts out to disk." @@ -25,9 +24,28 @@ (:method (text (format (eql :html))) text)) -(defun read-post (stream) - "Make a POST instance based on the data from STREAM." - ) +(defun read-post (in) + "Make a POST instance based on the data from the stream IN." + (flet ((check-header () + (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))) + (check-header) + (let ((args (loop for field in '("title" "tags" "date" "format") + for line = (read-line in nil) + when (not (search field line :test #'string=)) + do (error "The provided file lacks the expected header.") + appending (list (intern (string-upcase field) :keyword) + (aref (parse-field (read-line in)) 0))))) + (check-header) + (apply 'make-instance 'blog + (append args (list :content (slurp-remainder) + :slug (slugify (getf args :title)))))))) (defun write-post (slug post) "Write out the HTML for POST in SLUG.html."