diff --git a/coleslaw-static.asd b/coleslaw-static.asd new file mode 100644 index 0000000..4d9e64b --- /dev/null +++ b/coleslaw-static.asd @@ -0,0 +1,12 @@ +(defsystem :coleslaw-static + :name "coleslaw-static" + :description "Flexible Lisp Blogware, Static backend" + :version "0.0.1" + :maintainer "Brit Butler " + :author "Brit Butler " + :licence "LLGPL" + :depends-on (:coleslaw :zs3 :trivial-timers) + :components ((:module static + :components ((:file "coleslaw") + (:file "posts" + :depends-on ("coleslaw")))))) diff --git a/static/coleslaw.lisp b/static/coleslaw.lisp new file mode 100644 index 0000000..4e8870a --- /dev/null +++ b/static/coleslaw.lisp @@ -0,0 +1,19 @@ +(in-package :coleslaw) + +(defun static-init () + (setf *storage* (make-hash-table)) + (loop for table in '(:authors :comments :posts :indices :credentials) + do (unless (gethash table *storage*) + (setf (gethash table *storage*) (make-hash-table))))) + +(defmethod start-coleslaw (&rest options) + ) + +(defmethod stop-coleslaw (&rest options) + ) + +(defmethod get-credentials (name) + (gethash name (gethash :credentials *storage*))) + +(defmethod set-credentials (name credentials) + (setf (gethash name (gethash :credentials *storage*)) credentials)) diff --git a/static/comments.lisp b/static/comments.lisp new file mode 100644 index 0000000..fb7f3d6 --- /dev/null +++ b/static/comments.lisp @@ -0,0 +1,2 @@ +(in-package :coleslaw) + diff --git a/static/indices.lisp b/static/indices.lisp new file mode 100644 index 0000000..9987621 --- /dev/null +++ b/static/indices.lisp @@ -0,0 +1,13 @@ +(in-package :coleslaw) + +(defmethod find-index (id) + (gethash id (gethash :indices *storage*))) + +(defmethod add-index (index id) + (setf (find-index id) index)) + +(defmethod remove-index (id) + (setf (find-index id) nil)) + +(defmethod render-index (index) + ) diff --git a/static/posts.lisp b/static/posts.lisp new file mode 100644 index 0000000..28b81db --- /dev/null +++ b/static/posts.lisp @@ -0,0 +1,55 @@ +(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)) + :title title + :tags tags + :date date + :content content)) + +(defmethod add-post ((post post) id) + (setf (gethash id (gethash :posts *storage*)) post)) + +(defmethod remove-post (id) + (setf (gethash id (gethash :posts *storage*)) nil)) + +(defmethod render-post (id) + (flet ((fn (name) + (find-symbol name (theme-package)))) + (let* ((post (find-post id)) + (result (funcall (fn "POST") + (list :title (post-title post) + :tags (post-tags post) + :date (post-date post) + :content (post-content post) + :prev (post-prev post) + :next (post-next post))))) + result))) + +(defmethod find-post (id) + (gethash id (gethash :posts *storage*))) + +(defmethod find-by-tag (tag) + (let ((results nil)) + (loop for post being the hash-values in (gethash :posts *storage*) + do (when (search tag (post-tags post)) + (push post results))) + 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))))