From 1e34b55483cfbe8b2153dc2cbcd7f4bec59d281c Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Sun, 17 Apr 2011 23:53:11 -0400 Subject: [PATCH] Implement find-by-date, improve tag handling, minor cleanups and TODO updates. --- TODO | 8 +++----- plugins/import.lisp | 4 ++-- static/posts.lisp | 23 +++++++++++++++++++---- themes/hyde/index.tmpl | 4 ++-- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/TODO b/TODO index 0640e5d..082bf5c 100644 --- a/TODO +++ b/TODO @@ -12,14 +12,12 @@ Ideas: ;;;; DYNAMIC ;;;; STATIC +;;;; implement *output-dir*, render-site. ;;; posts -;; Implement find-by-date. -;; Make post-url not suck. -;; Consider having find-by-range collect all the hash-values in :posts -;; and return the range of that list rather than the posts matching start->end. -;; Consider storing tags as a list. +;; Make find-by-date, post-url not suck. ;;;; PLUGINS +;;;; implement disqus support ;;; import ;; add comment handling ... (when comments ...) ;; support old URLs via use of post-aliases? diff --git a/plugins/import.lisp b/plugins/import.lisp index 9db1a5a..5eb6383 100644 --- a/plugins/import.lisp +++ b/plugins/import.lisp @@ -42,12 +42,12 @@ object is determined by SERVICE.")) (parse-integer (third date)))))) ; year (when (public-p) (let ((new-post (make-post (node-val "title") - (format nil "~{~A~^, ~}" (node-val "category")) + (node-val "category") (make-timestamp (node-val "pubDate")) (regex-replace-all (string #\Newline) (node-val "content:encoded") "
") - :aliases (node-val "wp:post_id"))) + :aliases (parse-integer (node-val "wp:post_id")))) (comments (nodes "wp:comment"))) (add-post new-post (post-id new-post)))))) diff --git a/static/posts.lisp b/static/posts.lisp index 7201dc8..942aca6 100644 --- a/static/posts.lisp +++ b/static/posts.lisp @@ -9,7 +9,9 @@ :aliases aliases)) (defmethod add-post ((post post) id) - (setf (gethash id (gethash :posts *storage*)) post)) + (setf (gethash id (gethash :posts *storage*)) post) + (loop for tag in (post-tags post) + do (pushnew tag (gethash :tags-index *storage*) :test #'string=))) (defmethod remove-post (id) (setf (gethash id (gethash :posts *storage*)) nil)) @@ -18,16 +20,18 @@ (flet ((fn (name) (find-symbol name (theme-package))) (pretty-date (date) - (subseq (local-time:format-rfc1123-timestring nil date) 0 16))) + (subseq (local-time:format-rfc1123-timestring nil date) 0 16)) + (pretty-tags (tags) + (format nil "~{~A~^, ~}" tags))) (let* ((post (find-post id)) (result (funcall (fn "POST") (list :title (post-title post) - :tags (post-tags post) + :tags (pretty-tags (post-tags post)) :date (pretty-date (post-date post)) :content (post-content post) :prev (when (find-post (1- id)) (post-url (1- id))) - :next (when (find-post (1+ oid)) + :next (when (find-post (1+ id)) (post-url (1+ id))))))) result))) @@ -41,6 +45,17 @@ (push post results))) results)) +(defmethod find-by-date (date) + (let ((results nil) + (year (parse-integer (subseq date 0 4))) + (month (parse-integer (subseq date 5)))) + (loop for post being the hash-values in (gethash :posts *storage*) + do (let ((post-date (post-date post))) + (when (and (= year (local-time:timestamp-year post-date)) + (= month (local-time:timestamp-month post-date))) + (push post results)))) + results)) + (defmethod find-by-range (start end) (loop for id from start upto end collecting (find-post id))) diff --git a/themes/hyde/index.tmpl b/themes/hyde/index.tmpl index 82c022b..c3652d0 100644 --- a/themes/hyde/index.tmpl +++ b/themes/hyde/index.tmpl @@ -3,12 +3,12 @@ {template index} {if $taglinks}
-

This blog covers: {$taglinks |noAutoescape} +

This blog covers {$taglinks |noAutoescape}

{/if} {if $monthlinks}
-

View blogs from: {$monthlinks |noAutoescape} +

View posts from {$monthlinks |noAutoescape}

{/if}

{$title}