Browse Source

Factor render-index out of render-indices.

Brit Butler 12 years ago
parent
commit
2fb3ed1157
2 changed files with 19 additions and 19 deletions
  1. 1 0
      src/coleslaw.lisp
  2. 18 19
      src/indices.lisp

+ 1 - 0
src/coleslaw.lisp

56
         (run-program "cp -R ~a ." dir)))
56
         (run-program "cp -R ~a ." dir)))
57
     (do-ctypes (publish (make-keyword ctype)))
57
     (do-ctypes (publish (make-keyword ctype)))
58
     (render-indices)
58
     (render-indices)
59
+    (update-symlink "index.html" "1.html")
59
     (render-feeds (feeds *config*))))
60
     (render-feeds (feeds *config*))))
60
 
61
 
61
 (defgeneric deploy (staging)
62
 (defgeneric deploy (staging)

+ 18 - 19
src/indices.lisp

5
    (posts :initform nil :initarg :posts :accessor index-posts)
5
    (posts :initform nil :initarg :posts :accessor index-posts)
6
    (title :initform nil :initarg :title :accessor index-title)))
6
    (title :initform nil :initarg :title :accessor index-title)))
7
 
7
 
8
-(defmethod render ((object index) &key prev next)
9
-  (funcall (theme-fn 'index) (list :tags (all-tags)
10
-                                   :months (all-months)
11
-                                   :config *config*
12
-                                   :index object
13
-                                   :prev prev
14
-                                   :next next)))
15
-
16
 (defclass tag-index (index) ())
8
 (defclass tag-index (index) ())
17
 (defclass date-index (index) ())
9
 (defclass date-index (index) ())
18
 (defclass int-index (index) ())
10
 (defclass int-index (index) ())
26
 (defmethod page-url ((object int-index))
18
 (defmethod page-url ((object int-index))
27
   (format nil "~d" (index-id object)))
19
   (format nil "~d" (index-id object)))
28
 
20
 
21
+(defmethod render ((object index) &key prev next)
22
+  (funcall (theme-fn 'index) (list :tags (all-tags)
23
+                                   :months (all-months)
24
+                                   :config *config*
25
+                                   :index object
26
+                                   :prev prev
27
+                                   :next next)))
28
+
29
 (defun all-months ()
29
 (defun all-months ()
30
   "Retrieve a list of all months with published content."
30
   "Retrieve a list of all months with published content."
31
   (let ((months (mapcar (lambda (x) (subseq (content-date x) 0 7))
31
   (let ((months (mapcar (lambda (x) (subseq (content-date x) 0 7))
58
                               :posts (subseq content start end)
58
                               :posts (subseq content start end)
59
                               :title "Recent Posts")))
59
                               :title "Recent Posts")))
60
 
60
 
61
+(defun render-index (index &rest render-args)
62
+  "Render the given INDEX using RENDER-ARGS if provided."
63
+  (write-page (page-path index) (apply #'render-page index nil render-args)))
64
+
61
 (defun render-indices ()
65
 (defun render-indices ()
62
   "Render the indices to view content in groups of size N, by month, and by tag."
66
   "Render the indices to view content in groups of size N, by month, and by tag."
63
   (let ((results (by-date (hash-table-values *content*))))
67
   (let ((results (by-date (hash-table-values *content*))))
64
     (dolist (tag (all-tags))
68
     (dolist (tag (all-tags))
65
-      (let ((index (index-by-tag tag results)))
66
-        (write-page (page-path index) (render-page index))))
69
+      (render-index (index-by-tag tag results)))
67
     (dolist (month (all-months))
70
     (dolist (month (all-months))
68
-      (let ((index (index-by-month month results)))
69
-        (write-page (page-path index) (render-page index))))
71
+      (render-index (index-by-month month results)))
70
     (dotimes (i (ceiling (length results) 10))
72
     (dotimes (i (ceiling (length results) 10))
71
-      (let ((index (index-by-n i results)))
72
-        (write-page (page-path index)
73
-                    (render-page index nil
74
-                                 :prev (and (plusp i) i)
75
-                                 :next (and (< (* (1+ i) 10) (length results))
76
-                                            (+ 2 i)))))))
77
-  (update-symlink "index.html" "1.html"))
73
+      (render-index (index-by-n i results)
74
+                    :prev (and (plusp i) i)
75
+                    :next (and (< (* (1+ i) 10) (length results))
76
+                               (+ 2 i))))))