Sketch index rendering.
This commit is contained in:
parent
b92fb4d9b6
commit
2454656471
2 changed files with 47 additions and 22 deletions
|
@ -1,27 +1,53 @@
|
||||||
(in-package :coleslaw)
|
(in-package :coleslaw)
|
||||||
|
|
||||||
(defclass index ()
|
(defun taglinks ()
|
||||||
((id :initform nil :initarg :id
|
(let ((tags (remove-duplicates (mapcar #'post-tags *posts*))))
|
||||||
:accessor index-id)
|
(loop for tag in tags
|
||||||
(posts :initform nil :initarg :posts
|
collect (list :url (format nil "~a/tag/~a.html" (domain *config*) tag)
|
||||||
:accessor index-posts)))
|
:name tag))))
|
||||||
|
|
||||||
(defgeneric make-index (id posts)
|
(defun monthlinks ()
|
||||||
(:documentation "Create an INDEX with the given data."))
|
(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)
|
(defun render-index (posts)
|
||||||
(:documentation "Add POST to the index matching ID, creating INDEX if
|
(loop for post in posts
|
||||||
it does not exist."))
|
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)
|
(defun render-by-20 ()
|
||||||
(:documentation "Remove POST from the index matching ID, removing INDEX if
|
(flet ((by-20 (posts start)
|
||||||
it holds no more posts."))
|
(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)
|
(defun render-by-tag ()
|
||||||
(:documentation "Generate the final HTML for a given PAGE of the index ID."))
|
(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)
|
(defun render-by-month ())
|
||||||
(:documentation "Retrieve the index matching ID from *storage*."))
|
|
||||||
|
|
||||||
(defgeneric index-url (id page)
|
(defun render-indices ()
|
||||||
(:documentation "Return the URL for the PAGE of index with given ID."))
|
(render-by-20)
|
||||||
|
(render-by-tag)
|
||||||
|
(render-by-month))
|
||||||
|
|
|
@ -20,17 +20,16 @@
|
||||||
|
|
||||||
(defun read-post (stream)
|
(defun read-post (stream)
|
||||||
"Make a POST instance based on the data from STREAM."
|
"Make a POST instance based on the data from STREAM."
|
||||||
(make-instance 'post
|
|
||||||
:slug (make-slug post))
|
|
||||||
)
|
)
|
||||||
|
|
||||||
(defun write-post (slug post)
|
(defun write-post (slug post)
|
||||||
"Write out the HTML for POST in SLUG.html."
|
"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")
|
(funcall (theme-fn "POST")
|
||||||
(list :title (post-title post)
|
(list :title (post-title post)
|
||||||
:tags (post-tags post)
|
:tags (post-tags post)
|
||||||
:date (post-date post)
|
:date (post-date post)
|
||||||
:content (post-content post)
|
:content (post-content post)
|
||||||
|
; TODO: Populate prev and next with links.
|
||||||
:prev nil
|
:prev nil
|
||||||
:next nil))))
|
:next nil))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue