|
@@ -1,18 +1,31 @@
|
1
|
1
|
(in-package :coleslaw)
|
2
|
2
|
|
3
|
3
|
(defclass index ()
|
4
|
|
- ((path :initform nil :initarg :path :accessor index-path)
|
|
4
|
+ ((id :initform nil :initarg :id :accessor index-id)
|
5
|
5
|
(posts :initform nil :initarg :posts :accessor index-posts)
|
6
|
6
|
(title :initform nil :initarg :title :accessor index-title)))
|
7
|
7
|
|
8
|
|
-(defmethod render ((content index) &key prev next)
|
|
8
|
+(defmethod render ((object index) &key prev next)
|
9
|
9
|
(funcall (theme-fn 'index) (list :tags (all-tags)
|
10
|
10
|
:months (all-months)
|
11
|
11
|
:config *config*
|
12
|
|
- :index content
|
|
12
|
+ :index object
|
13
|
13
|
:prev prev
|
14
|
14
|
:next next)))
|
15
|
15
|
|
|
16
|
+(defclass tag-index (index) ())
|
|
17
|
+(defclass date-index (index) ())
|
|
18
|
+(defclass int-index (index) ())
|
|
19
|
+
|
|
20
|
+(defmethod page-path ((object index))
|
|
21
|
+ (rel-path (staging *config*) (index-id object)))
|
|
22
|
+(defmethod page-path ((object tag-index))
|
|
23
|
+ (rel-path (staging *config*) "tag/~a.html" (index-id object)))
|
|
24
|
+(defmethod page-path ((object date-index))
|
|
25
|
+ (rel-path (staging *config*) "date/~a.html" (index-id object)))
|
|
26
|
+(defmethod page-path ((object int-index))
|
|
27
|
+ (rel-path (staging *config*) "~d.html" (index-id object)))
|
|
28
|
+
|
16
|
29
|
(defun all-months ()
|
17
|
30
|
"Retrieve a list of all months with published posts."
|
18
|
31
|
(sort (remove-duplicates (mapcar (lambda (x) (get-month (post-date x)))
|
|
@@ -36,35 +49,40 @@
|
36
|
49
|
"Return an index of all POSTS matching the given TAG."
|
37
|
50
|
(let ((content (remove-if-not (lambda (post) (member tag (post-tags post)
|
38
|
51
|
:test #'string=)) posts)))
|
39
|
|
- (make-instance 'index :path (format nil "tag/~a.html" tag)
|
40
|
|
- :posts content
|
41
|
|
- :title (format nil "Posts tagged ~a" tag))))
|
|
52
|
+ (make-instance 'tag-index :id tag
|
|
53
|
+ :posts content
|
|
54
|
+ :title (format nil "Posts tagged ~a" tag))))
|
42
|
55
|
|
43
|
56
|
(defun index-by-month (month posts)
|
44
|
57
|
"Return an index of all POSTS matching the given MONTH."
|
45
|
58
|
(let ((content (remove-if-not (lambda (post) (search month (post-date post)))
|
46
|
59
|
posts)))
|
47
|
|
- (make-instance 'index :path (format nil "date/~a.html" month)
|
48
|
|
- :posts content
|
49
|
|
- :title (format nil "Posts from ~a" month))))
|
|
60
|
+ (make-instance 'date-index :id month
|
|
61
|
+ :posts content
|
|
62
|
+ :title (format nil "Posts from ~a" month))))
|
50
|
63
|
|
51
|
64
|
(defun index-by-n (i posts &optional (step 10))
|
52
|
65
|
"Return the index for the Ith page of POSTS in reverse chronological order."
|
53
|
|
- (make-instance 'index :path (format nil "~d.html" (1+ i))
|
54
|
|
- :posts (let ((index (* step i)))
|
55
|
|
- (subseq posts index (min (length posts)
|
56
|
|
- (+ index step))))
|
57
|
|
- :title "Recent Posts"))
|
|
66
|
+ (make-instance 'int-index :id (1+ i)
|
|
67
|
+ :posts (let ((index (* step i)))
|
|
68
|
+ (subseq posts index (min (length posts)
|
|
69
|
+ (+ index step))))
|
|
70
|
+ :title "Recent Posts"))
|
58
|
71
|
|
59
|
72
|
(defun render-indices ()
|
60
|
73
|
"Render the indices to view posts in groups of size N, by month, and by tag."
|
61
|
74
|
(let ((posts (by-date (hash-table-values *posts*))))
|
62
|
75
|
(dolist (tag (all-tags))
|
63
|
|
- (render-page (index-by-tag tag posts)))
|
|
76
|
+ (let ((index (index-by-tag tag posts)))
|
|
77
|
+ (write-page (page-path index) (render-page index))))
|
64
|
78
|
(dolist (month (all-months))
|
65
|
|
- (render-page (index-by-month month posts)))
|
|
79
|
+ (let ((index (index-by-month month posts)))
|
|
80
|
+ (write-page (page-path index) (render-page index))))
|
66
|
81
|
(dotimes (i (ceiling (length posts) 10))
|
67
|
|
- (render-page (index-by-n i posts) nil
|
68
|
|
- :prev (and (plusp i) i)
|
69
|
|
- :next (and (< (* (1+ i) 10) (length posts)) (+ 2 i)))))
|
|
82
|
+ (let ((index (index-by-n i posts)))
|
|
83
|
+ (write-page (page-path index)
|
|
84
|
+ (render-page index nil
|
|
85
|
+ :prev (and (plusp i) i)
|
|
86
|
+ :next (and (< (* (1+ i) 10) (length posts))
|
|
87
|
+ (+ 2 i)))))))
|
70
|
88
|
(update-symlink "index.html" "1.html"))
|