|
@@ -1,13 +1,61 @@
|
1
|
1
|
(in-package :coleslaw)
|
2
|
2
|
|
3
|
|
-(defmethod find-index (id)
|
4
|
|
- (gethash id (gethash :indices *storage*)))
|
|
3
|
+(defun monthlinks ()
|
|
4
|
+ (loop for month in (gethash :months-index *storage*)
|
|
5
|
+ collect (cons (index-url :date month) month) into months
|
|
6
|
+ finally (return
|
|
7
|
+ (pretty-list (mapcar (lambda (consp)
|
|
8
|
+ (format nil "<a href=\"~a\">~a</a>"
|
|
9
|
+ (car consp) (cdr consp)))
|
|
10
|
+ months)))))
|
5
|
11
|
|
6
|
|
-(defmethod add-index (index id)
|
7
|
|
- (setf (find-index id) index))
|
|
12
|
+(defun taglinks ()
|
|
13
|
+ (loop for tag in (gethash :tags-index *storage*)
|
|
14
|
+ collect (cons (index-url :tag tag) tag) into tags
|
|
15
|
+ finally (return
|
|
16
|
+ (pretty-list (mapcar (lambda (consp)
|
|
17
|
+ (format nil "<a href=\"~a\">~a</a>"
|
|
18
|
+ (car consp) (cdr consp)))
|
|
19
|
+ tags)))))
|
8
|
20
|
|
9
|
|
-(defmethod remove-index (id)
|
10
|
|
- (setf (find-index id) nil))
|
|
21
|
+(defun index-title (id &optional page)
|
|
22
|
+ (case id
|
|
23
|
+ (:range "Recent Posts")
|
|
24
|
+ (:date (format nil "Posts from ~A" page))
|
|
25
|
+ (:tag (format nil "Posts tagged ~A" page))))
|
11
|
26
|
|
12
|
|
-(defmethod render-index (index)
|
13
|
|
- )
|
|
27
|
+(defun index-posts (id page)
|
|
28
|
+ (case id
|
|
29
|
+ (:range (let* ((count (hash-table-count (gethash :posts *storage*)))
|
|
30
|
+ (start (- count (* 10 (1- page))))
|
|
31
|
+ (end (- start 9)))
|
|
32
|
+ (remove nil (find-by-range start end))))
|
|
33
|
+ (:date (find-by-date page))
|
|
34
|
+ (:tag (find-by-tag page))))
|
|
35
|
+
|
|
36
|
+(defmethod render-index (id page)
|
|
37
|
+ (let* ((posts (index-posts id page))
|
|
38
|
+ (content (funcall (find-symbol "INDEX" (theme-package))
|
|
39
|
+ (list :taglinks (taglinks)
|
|
40
|
+ :monthlinks (monthlinks)
|
|
41
|
+ :title (index-title id page)
|
|
42
|
+ :posts (loop for post in posts collect
|
|
43
|
+ (list :url (post-url (post-id post))
|
|
44
|
+ :title (post-title post)
|
|
45
|
+ :date (pretty-date (post-date post))
|
|
46
|
+ :contents (post-content post)))
|
|
47
|
+ :prev (when (and (numberp id)
|
|
48
|
+ (index-posts id (1- page)))
|
|
49
|
+ (index-url id (1- page)))
|
|
50
|
+ :next (when (and (numberp id)
|
|
51
|
+ (index-posts id (1+ page)))
|
|
52
|
+ (index-url id (1+ page)))))))
|
|
53
|
+ content))
|
|
54
|
+
|
|
55
|
+(defmethod index-url (id page)
|
|
56
|
+ (flet ((keyword-name (keyword)
|
|
57
|
+ (format nil "~A" keyword)))
|
|
58
|
+ (if (member id '(:date :tag))
|
|
59
|
+ (concatenate 'string *site-root* "/"
|
|
60
|
+ (string-downcase (keyword-name id)) "/" page)
|
|
61
|
+ (concatenate 'string *site-root* "/page/" (write-to-string page)))))
|