Generate fresh IDs but preserve old ones via 'alias' system. Add post-url, update TODO.
This commit is contained in:
parent
2aa8b9d298
commit
ae9d51c79b
5 changed files with 38 additions and 27 deletions
15
TODO
15
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"
|
||||
|
|
|
@ -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")
|
||||
"<br>")
|
||||
: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))))))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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."))
|
||||
|
|
|
@ -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))))))
|
||||
|
|
Loading…
Add table
Reference in a new issue