Fix handling of newlines in import and errors in post template.

This commit is contained in:
Brit Butler 2011-04-17 19:07:04 -04:00
parent ce344d703e
commit 2aa8b9d298
3 changed files with 33 additions and 25 deletions

View file

@ -1,15 +1,20 @@
(asdf:oos 'asdf:load-op 'cxml) (asdf:oos 'asdf:load-op 'cxml)
(asdf:oos 'asdf:load-op 'split-sequence) (asdf:oos 'asdf:load-op 'split-sequence)
(asdf:oos 'asdf:load-op 'local-time) (asdf:oos 'asdf:load-op 'local-time)
(asdf:oos 'asdf:load-op 'cl-ppcre)
(defpackage :coleslaw-import (defpackage :coleslaw-import
(:use :cl :coleslaw :cxml) (:use :cl :coleslaw :cxml)
(:import-from :local-time #:+short-month-names+ (:import-from :local-time #:+short-month-names+
#:encode-timestamp) #:encode-timestamp)
(:import-from :split-sequence #:split-sequence)) (:import-from :split-sequence #:split-sequence)
(:import-from :cl-ppcre #:regex-replace-all))
(in-package :coleslaw-import) (in-package :coleslaw-import)
;; TODO:
;; add comment handling ... (when comments ...)
(defgeneric import-post (service post) (defgeneric import-post (service post)
(:documentation "Import POST into *storage*. The method to construct the POST (:documentation "Import POST into *storage*. The method to construct the POST
object is determined by SERVICE.")) object is determined by SERVICE."))
@ -42,11 +47,11 @@ object is determined by SERVICE."))
(let ((new-post (make-post (node-val "title") (let ((new-post (make-post (node-val "title")
(format nil "~{~A~^, ~}" (node-val "category")) (format nil "~{~A~^, ~}" (node-val "category"))
(make-timestamp (node-val "pubDate")) (make-timestamp (node-val "pubDate"))
(node-val "content:encoded") (regex-replace-all (string #\Newline)
(node-val "content:encoded")
"<br>")
:id (parse-integer (node-val "wp:post_id")))) :id (parse-integer (node-val "wp:post_id"))))
(comments (nodes "wp:comment"))) (comments (nodes "wp:comment")))
;; TODO:
;; add comment handling ... (when comments ...)
(add-post new-post (post-id new-post)))))) (add-post new-post (post-id new-post))))))
(defgeneric import-posts (service filepath) (defgeneric import-posts (service filepath)

View file

@ -28,15 +28,18 @@
(defmethod render-post (id) (defmethod render-post (id)
(flet ((fn (name) (flet ((fn (name)
(find-symbol name (theme-package)))) (find-symbol name (theme-package)))
(pretty-date (date)
(subseq (local-time:format-rfc1123-timestring nil date) 0 16)))
(let* ((post (find-post id)) (let* ((post (find-post id))
(result (funcall (fn "POST") (result (funcall (fn "POST")
(list :title (post-title post) (list :title (post-title post)
:tags (post-tags post) :tags (post-tags post)
:date (post-date post) :date (pretty-date (post-date post))
:content (post-content post) :content (post-content post)
:prev (post-prev post) ; :prev (post-prev post)
:next (post-next post))))) ; :next (post-next post)
))))
result))) result)))
(defmethod find-post (id) (defmethod find-post (id)

View file

@ -1,23 +1,23 @@
{namespace coleslaw.theme.hyde} {namespace coleslaw.theme.hyde}
{template post} {template post}
<div class="article-meta"> <div class="article-meta">{\n}
<h1 class="title" {$title}> <h1 class="title">{$title}</h1>{\n}
<div class="tags" <div class="tags">{\n}
Tagged as: {$tags} Tagged as {$tags}
</div> </div>{\n}
<div class="date"> <div class="date">{\n}
Written on {$date} Written on {$date}
</div> </div>{\n}
<div class="article-content"> </div>{\n}
{$content |noAutoescape} <div class="article-content">{\n}
</div> {$content |noAutoescape}
<div class="relative-nav"> </div>{\n}
{if $prev} <a href="{$prev}">Previous</a> {/if} <div class="relative-nav">{\n}
{if $next} <a href="{$next}">Next</a> {/if} {if $prev} <a href="{$prev}">Previous</a> {/if}
</div> {if $next} <a href="{$next}">Next</a> {/if}
{if $comments} </div>{\n}
{if $comments}
<div class="comments">{$comments |noAutoescape}</div> <div class="comments">{$comments |noAutoescape}</div>
{/if} {/if}
</div>
{/template} {/template}