2011-04-16 15:45:37 -04:00
|
|
|
(in-package :coleslaw)
|
|
|
|
|
2012-08-20 11:53:39 -04:00
|
|
|
(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))))
|
2011-04-16 15:45:37 -04:00
|
|
|
|
2012-08-20 11:53:39 -04:00
|
|
|
(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))))
|
2011-04-22 17:16:42 -04:00
|
|
|
|
2012-08-20 16:55:47 -04:00
|
|
|
(defun write-index (posts filename title)
|
2012-08-20 12:06:01 -04:00
|
|
|
(let ((content (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)))))
|
|
|
|
(render-page filename
|
|
|
|
(funcall (theme-fn "INDEX")
|
|
|
|
(list :taglinks (taglinks)
|
|
|
|
:monthlinks (monthlinks)
|
2012-08-20 16:55:47 -04:00
|
|
|
:title title
|
2012-08-20 12:06:01 -04:00
|
|
|
:posts content
|
|
|
|
; TODO: Populate prev and next with links.
|
|
|
|
:prev nil
|
|
|
|
:next nil)))))
|
2011-04-22 17:16:42 -04:00
|
|
|
|
2012-08-20 11:53:39 -04:00
|
|
|
(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))
|
2012-08-20 16:55:47 -04:00
|
|
|
do (write-index (by-20 posts i) (format nil "~d.html" i) "Recent Posts")))))
|
2011-04-16 15:45:37 -04:00
|
|
|
|
2012-08-20 11:53:39 -04:00
|
|
|
(defun render-by-tag ()
|
|
|
|
(let ((tags (remove-duplicates (mapcan #'post-tags *posts*) :test #'string=)))
|
|
|
|
(loop for tag in tags
|
2012-08-20 16:55:47 -04:00
|
|
|
do (flet ((match-tag (post)
|
|
|
|
(member tag post :test #'string= :key #'post-tags)))
|
|
|
|
(let ((posts (remove-if-not #'match-tag posts)))
|
|
|
|
(write-index posts (format nil "tag/~a.html" tag)
|
|
|
|
(format nil "Posts tagged ~a" tag)))))))
|
2011-04-16 15:45:37 -04:00
|
|
|
|
2012-08-20 12:06:01 -04:00
|
|
|
(defun render-by-month ()
|
2012-08-20 16:55:47 -04:00
|
|
|
(let ((months (remove-duplicates (mapcar (lambda (x) (subseq (post-date x) 0 7))
|
|
|
|
*posts*) :test #'string=)))
|
2012-08-20 12:06:01 -04:00
|
|
|
(loop for month in months
|
2012-08-20 16:55:47 -04:00
|
|
|
do (let ((posts (remove-if-not (lambda (x) (search month (post-date x))
|
|
|
|
*posts*))))
|
|
|
|
(write-index posts (format nil "date/~a.html" (subseq month 0 7))
|
|
|
|
(format nil "Posts from ~a" (subseq month 0 7)))))))
|
2011-04-19 00:34:17 -04:00
|
|
|
|
2012-08-20 11:53:39 -04:00
|
|
|
(defun render-indices ()
|
|
|
|
(render-by-20)
|
2012-08-20 16:55:47 -04:00
|
|
|
(render-by-tag)
|
|
|
|
(render-by-month))
|