From ae9d51c79bcd784a0097592604047c2362b18e70 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Sun, 17 Apr 2011 22:22:14 -0400 Subject: [PATCH] Generate fresh IDs but preserve old ones via 'alias' system. Add post-url, update TODO. --- TODO | 15 +++++++++++++++ plugins/import.lisp | 5 +---- src/packages.lisp | 2 ++ src/posts.lisp | 7 ++++++- static/posts.lisp | 36 ++++++++++++++---------------------- 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/TODO b/TODO index 06c25a9..0640e5d 100644 --- a/TODO +++ b/TODO @@ -9,6 +9,21 @@ Ideas: ;; consider add-to-index/setf-index, create-index, create-post. ;; then ensure the indices API is okay and GET GOING. +;;;; DYNAMIC + +;;;; STATIC +;;; 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. + +;;;; PLUGINS +;;; import +;; add comment handling ... (when comments ...) +;; support old URLs via use of post-aliases? + ;;;; rendering hooks (eg. :pygmentize, :xpost-lj?) ;; may need pre- and post- but for now stick to post-. ;; get run on rendered html before "storage" diff --git a/plugins/import.lisp b/plugins/import.lisp index e371b5d..9db1a5a 100644 --- a/plugins/import.lisp +++ b/plugins/import.lisp @@ -12,9 +12,6 @@ (in-package :coleslaw-import) -;; TODO: -;; add comment handling ... (when comments ...) - (defgeneric import-post (service post) (:documentation "Import POST into *storage*. The method to construct the POST object is determined by SERVICE.")) @@ -50,7 +47,7 @@ object is determined by SERVICE.")) (regex-replace-all (string #\Newline) (node-val "content:encoded") "
") - :id (parse-integer (node-val "wp:post_id")))) + :aliases (node-val "wp:post_id"))) (comments (nodes "wp:comment"))) (add-post new-post (post-id new-post)))))) diff --git a/src/packages.lisp b/src/packages.lisp index aa23d38..a19258d 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -21,12 +21,14 @@ #:find-by-tag #:find-by-date #:find-by-range + #:post-url #:post-id #:post-title #:post-tags #:post-date #:post-content + #:post-aliases ;; comments #:make-comment diff --git a/src/posts.lisp b/src/posts.lisp index 8e8867a..a380ba7 100644 --- a/src/posts.lisp +++ b/src/posts.lisp @@ -10,7 +10,9 @@ (date :initform nil :initarg :date :accessor post-date) (content :initform nil :initarg :content - :accessor post-content))) + :accessor post-content) + (aliases :initform nil :initarg :aliases + :accessor post-aliases))) (defgeneric make-post (title tags date content &key id &allow-other-keys) (:documentation "Create a POST with the given data.")) @@ -36,3 +38,6 @@ (defgeneric find-by-range (start end) (:documentation "Retrieve all posts from *storage* with ids between START and END.")) + +(defgeneric post-url (id) + (:documentation "Return the URL for the post with the given ID.")) diff --git a/static/posts.lisp b/static/posts.lisp index c4c17d3..7201dc8 100644 --- a/static/posts.lisp +++ b/static/posts.lisp @@ -1,24 +1,12 @@ (in-package :coleslaw) -;; TODO -;; How are we handling next/prev + ids? -;; Implement find-by-date. -;; 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. - -(defmethod make-post :before (title tags date content &key id &allow-other-keys) - (when id - (let ((index (gethash :posts-index *storage* 0))) - (unless (<= id index) - (setf (gethash :posts-index *storage*) (1+ id)))))) - -(defmethod make-post (title tags date content &key id) - (make-instance 'post :id (or id (gethash :posts-index *storage* 0)) +(defmethod make-post (title tags date content &key id aliases) + (make-instance 'post :id (incf (gethash :posts-index *storage* 0)) :title title :tags tags :date date - :content content)) + :content content + :aliases aliases)) (defmethod add-post ((post post) id) (setf (gethash id (gethash :posts *storage*)) post)) @@ -37,9 +25,10 @@ :tags (post-tags post) :date (pretty-date (post-date post)) :content (post-content post) - ; :prev (post-prev post) - ; :next (post-next post) - )))) + :prev (when (find-post (1- id)) + (post-url (1- id))) + :next (when (find-post (1+ oid)) + (post-url (1+ id))))))) result))) (defmethod find-post (id) @@ -53,6 +42,9 @@ results)) (defmethod find-by-range (start end) - (loop for i from start upto end - collecting (find-post id) into results - finally (return (remove nil results)))) + (loop for id from start upto end collecting (find-post id))) + +(defmethod post-url (id) + (flet ((escape (str) + (substitute #\- #\Space str))) + (concatenate 'string *site-root* (escape (post-title (find-post id))))))