Ver código fonte

Fix indices and feeds.

Brit Butler 12 anos atrás
pai
commit
65933f731f
4 arquivos alterados com 48 adições e 28 exclusões
  1. 2 2
      src/coleslaw.lisp
  2. 7 5
      src/feeds.lisp
  3. 37 19
      src/indices.lisp
  4. 2 2
      src/posts.lisp

+ 2 - 2
src/coleslaw.lisp

@@ -12,8 +12,8 @@
12 12
       (with-output-to-string (str)
13 13
         (3bmd:parse-string-and-print-to-stream text str)))))
14 14
 
15
-(defgeneric page-path (content)
16
-  (:documentation "The path to store CONTENT at once rendered."))
15
+(defgeneric page-path (object)
16
+  (:documentation "The path to store OBJECT at once rendered."))
17 17
 
18 18
 (defun render-page (content &optional theme-fn &rest render-args)
19 19
   "Render the given CONTENT to disk using THEME-FN if supplied.

+ 7 - 5
src/feeds.lisp

@@ -12,11 +12,13 @@
12 12
   (flet ((first-10 (list)
13 13
            (subseq list 0 (min (length list) 10))))
14 14
     (let* ((by-date (by-date (hash-table-values *posts*)))
15
-           (posts (first-10 by-date)))
16
-      (render-page (make-instance 'index :path "rss.xml" :posts posts) :rss-feed)
17
-      (render-page (make-instance 'index :path "feed.atom" :posts posts) :atom-feed)
15
+           (posts (first-10 by-date))
16
+           (rss (make-instance 'index :id "rss.xml" :posts posts))
17
+           (atom (make-instance 'index :id "feed.atom" :posts posts)))
18
+      (write-page (page-path rss) (render-page rss :rss-feed))
19
+      (write-page (page-path atom) (render-page atom :atom-feed))
18 20
       (dolist (feed feeds)
19 21
         (let ((index (index-by-tag feed by-date)))
20
-          (setf (index-path index) (format nil "tag/~a-rss.xml" feed)
22
+          (setf (index-id index) (format nil "tag/~a.xml" feed)
21 23
                 (index-posts index) (first-10 (index-posts index)))
22
-          (render-page index :rss))))))
24
+          (write-page (page-path index) (render-page index :rss-feed)))))))

+ 37 - 19
src/indices.lisp

@@ -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"))

+ 2 - 2
src/posts.lisp

@@ -17,8 +17,8 @@
17 17
                                   :prev prev
18 18
                                   :next next)))
19 19
 
20
-(defmethod page-path ((post post))
21
-  (rel-path (staging *config*) "posts/~a.html" (post-slug post)))
20
+(defmethod page-path ((object post))
21
+  (rel-path (staging *config*) "posts/~a.html" (post-slug object)))
22 22
 
23 23
 (defun read-post (in)
24 24
   "Make a POST instance based on the data from the stream IN."