From 2454656471131f72e7cd64dcac5603f9dccb8cab Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Mon, 20 Aug 2012 11:53:39 -0400 Subject: [PATCH] Sketch index rendering. --- src/indices.lisp | 64 ++++++++++++++++++++++++++++++++++-------------- src/posts.lisp | 5 ++-- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/indices.lisp b/src/indices.lisp index 3936b10..3be76ce 100644 --- a/src/indices.lisp +++ b/src/indices.lisp @@ -1,27 +1,53 @@ (in-package :coleslaw) -(defclass index () - ((id :initform nil :initarg :id - :accessor index-id) - (posts :initform nil :initarg :posts - :accessor index-posts))) +(defun taglinks () + (let ((tags (remove-duplicates (mapcar #'post-tags *posts*)))) + (loop for tag in tags + collect (list :url (format nil "~a/tag/~a.html" (domain *config*) tag) + :name tag)))) -(defgeneric make-index (id posts) - (:documentation "Create an INDEX with the given data.")) +(defun monthlinks () + (let ((months (mapcar (lambda (x) (get-month (post-date x))) *posts*))) + (loop for month in months + collect (list :url (format nil "~a/month/~a.html" (domain *config*) month) + :name month)))) -(defgeneric add-to-index (id post) - (:documentation "Add POST to the index matching ID, creating INDEX if -it does not exist.")) +(defun render-index (posts) + (loop for post in posts + collect (list :url (format nil "~a/posts/~a.html" + (domain *config*) (post-slug post)) + :title (post-title post) + :date (post-date post) + :contents (post-contents post)))) -(defgeneric remove-from-index (id post) - (:documentation "Remove POST from the index matching ID, removing INDEX if -it holds no more posts.")) +(defun render-by-20 () + (flet ((by-20 (posts start) + (let ((index (* 20 (1- start)))) + (subseq posts index (min (length posts) (+ index 19)))))) + (let ((posts (sort *posts* #'string> :key #'post-date))) + (loop for i from 1 then (1+ i) + until (> (* (1- i) 20) (length posts)) + do (render-page (format nil "~d.html" i) + (funcall (theme-fn "INDEX") + (list :taglinks (taglinks) + :monthlinks (monthlinks) + :posts (render-index (by-20 posts i)) + ; TODO: Populate prev and next with links. + :prev nil + :next nil))))))) -(defgeneric render-index (id page) - (:documentation "Generate the final HTML for a given PAGE of the index ID.")) +(defun render-by-tag () + (let ((tags (remove-duplicates (mapcan #'post-tags *posts*) :test #'string=))) + (loop for tag in tags + do (let ((posts (remove-if-not (lambda (x) + (member tag x :test #'string= + :key #'post-tags)) + posts))) + (render-index posts))))) -(defgeneric find-index (id) - (:documentation "Retrieve the index matching ID from *storage*.")) +(defun render-by-month ()) -(defgeneric index-url (id page) - (:documentation "Return the URL for the PAGE of index with given ID.")) +(defun render-indices () + (render-by-20) + (render-by-tag) + (render-by-month)) diff --git a/src/posts.lisp b/src/posts.lisp index 20205d0..76e7565 100644 --- a/src/posts.lisp +++ b/src/posts.lisp @@ -20,17 +20,16 @@ (defun read-post (stream) "Make a POST instance based on the data from STREAM." - (make-instance 'post - :slug (make-slug post)) ) (defun write-post (slug post) "Write out the HTML for POST in SLUG.html." - (render-page (format nil "~a.html" slug) + (render-page (format nil "posts/~a.html" slug) (funcall (theme-fn "POST") (list :title (post-title post) :tags (post-tags post) :date (post-date post) :content (post-content post) + ; TODO: Populate prev and next with links. :prev nil :next nil))))