Implement find-by-date, improve tag handling, minor cleanups and TODO updates.

This commit is contained in:
Brit Butler 2011-04-17 23:53:11 -04:00
parent ae9d51c79b
commit 1e34b55483
4 changed files with 26 additions and 13 deletions

8
TODO
View file

@ -12,14 +12,12 @@ Ideas:
;;;; DYNAMIC ;;;; DYNAMIC
;;;; STATIC ;;;; STATIC
;;;; implement *output-dir*, render-site.
;;; posts ;;; posts
;; Implement find-by-date. ;; Make find-by-date, post-url not suck.
;; 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.
;;;; PLUGINS ;;;; PLUGINS
;;;; implement disqus support
;;; import ;;; import
;; add comment handling ... (when comments ...) ;; add comment handling ... (when comments ...)
;; support old URLs via use of post-aliases? ;; support old URLs via use of post-aliases?

View file

@ -42,12 +42,12 @@ object is determined by SERVICE."))
(parse-integer (third date)))))) ; year (parse-integer (third date)))))) ; year
(when (public-p) (when (public-p)
(let ((new-post (make-post (node-val "title") (let ((new-post (make-post (node-val "title")
(format nil "~{~A~^, ~}" (node-val "category")) (node-val "category")
(make-timestamp (node-val "pubDate")) (make-timestamp (node-val "pubDate"))
(regex-replace-all (string #\Newline) (regex-replace-all (string #\Newline)
(node-val "content:encoded") (node-val "content:encoded")
"<br>") "<br>")
:aliases (node-val "wp:post_id"))) :aliases (parse-integer (node-val "wp:post_id"))))
(comments (nodes "wp:comment"))) (comments (nodes "wp:comment")))
(add-post new-post (post-id new-post)))))) (add-post new-post (post-id new-post))))))

View file

@ -9,7 +9,9 @@
:aliases aliases)) :aliases aliases))
(defmethod add-post ((post post) id) (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) (defmethod remove-post (id)
(setf (gethash id (gethash :posts *storage*)) nil)) (setf (gethash id (gethash :posts *storage*)) nil))
@ -18,16 +20,18 @@
(flet ((fn (name) (flet ((fn (name)
(find-symbol name (theme-package))) (find-symbol name (theme-package)))
(pretty-date (date) (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)) (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 (pretty-tags (post-tags post))
:date (pretty-date (post-date post)) :date (pretty-date (post-date post))
:content (post-content post) :content (post-content post)
:prev (when (find-post (1- id)) :prev (when (find-post (1- id))
(post-url (1- id))) (post-url (1- id)))
:next (when (find-post (1+ oid)) :next (when (find-post (1+ id))
(post-url (1+ id))))))) (post-url (1+ id)))))))
result))) result)))
@ -41,6 +45,17 @@
(push post results))) (push post results)))
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) (defmethod find-by-range (start end)
(loop for id from start upto end collecting (find-post id))) (loop for id from start upto end collecting (find-post id)))

View file

@ -3,12 +3,12 @@
{template index} {template index}
{if $taglinks} {if $taglinks}
<div id="tagsoup"> <div id="tagsoup">
<p>This blog covers: {$taglinks |noAutoescape} <p>This blog covers {$taglinks |noAutoescape}
</div> </div>
{/if} {/if}
{if $monthlinks} {if $monthlinks}
<div id="monthsoup"> <div id="monthsoup">
<p>View blogs from: {$monthlinks |noAutoescape} <p>View posts from {$monthlinks |noAutoescape}
</div> </div>
{/if} {/if}
<h1>{$title}</h1> <h1>{$title}</h1>