Procházet zdrojové kódy

Assorted cleanups.

Brit Butler před 12 roky
rodič
revize
c7b36f65c3
3 změnil soubory, kde provedl 26 přidání a 31 odebrání
  1. 8 0
      src/content.lisp
  2. 11 18
      src/feeds.lisp
  3. 7 13
      src/indices.lisp

+ 8 - 0
src/content.lisp

@@ -25,6 +25,14 @@
25 25
   "Create an instance of CONTENT-TYPE with the given ARGS."
26 26
   (apply 'make-instance content-type args))
27 27
 
28
+(defun tag-p (tag obj)
29
+  "Test if OBJ is tagged with TAG."
30
+  (member tag (content-tags obj) :test #'tag-slug=))
31
+
32
+(defun month-p (month obj)
33
+  "Test if OBJ was written in MONTH."
34
+  (search month (content-date obj)))
35
+
28 36
 (defgeneric discover (content-type)
29 37
   (:documentation "Load all content of the given CONTENT-TYPE from disk."))
30 38
 

+ 11 - 18
src/feeds.lisp

@@ -4,24 +4,16 @@
4 4
   "Make a RFC1123 pubdate representing the current time."
5 5
   (local-time:format-rfc1123-timestring nil (local-time:now)))
6 6
 
7
-(defun first-10 (list)
8
-  "Get up to the first 10 items in LIST."
9
-  (subseq list 0 (min (length list) 10)))
10
-
11
-(defun make-tag-feed (tag posts)
12
-  "Make an RSS feed for the given TAG and POSTS."
13
-  (flet ((valid-p (obj) (member tag (content-tags obj) :test #'tag-slug=)))
14
-    (make-instance 'tag-index :id (format nil "~A-rss.xml" (tag-slug tag))
15
-                   :posts (first-10 (remove-if-not #'valid-p posts)))))
16
-
17 7
 (defun render-feed (posts &key path template tag)
18
-  "Given a PATH, TEMPLATE, and possibly a TAG, render the appropriate feed."
19
-  (let ((template (theme-fn template "feeds"))
20
-        (index (if tag
21
-                   (make-tag-feed tag posts)
22
-                   (make-instance 'index :id path
23
-                                  :posts (first-10 posts)))))
24
-    (write-page (page-path index) (render-page index template))))
8
+  (flet ((first-10 (list) (subseq list 0 (min (length list) 10)))
9
+         (tag-posts (list) (remove-if-not (lambda (x) (tag-p tag x)) list)))
10
+    (let ((template (theme-fn template "feeds"))
11
+          (index (if tag
12
+                     (make-instance 'tag-index :id path
13
+                                    :posts (first-10 (tag-posts posts)))
14
+                     (make-instance 'index :id path
15
+                                    :posts (first-10 posts)))))
16
+      (write-page (page-path index) (render-page index template)))))
25 17
 
26 18
 (defun render-feeds (tag-feeds)
27 19
   "Render the default RSS and ATOM feeds along with any TAG-FEEDS."
@@ -30,5 +22,6 @@
30 22
                     (:path "feed.atom" :template :atom-feed)))
31 23
       (apply #'render-feed posts feed))
32 24
     (dolist (feed tag-feeds)
33
-      (apply #'render-feed posts (list :tag (make-tag feed)
25
+      (apply #'render-feed posts (list :path (format nil "~A-rss.xml" feed)
26
+                                       :tag (make-tag feed)
34 27
                                        :template :rss-feed)))))

+ 7 - 13
src/indices.lisp

@@ -28,7 +28,7 @@
28 28
 
29 29
 (defun all-months ()
30 30
   "Retrieve a list of all months with published content."
31
-  (let ((months (mapcar (lambda (x) (get-month (content-date x)))
31
+  (let ((months (mapcar (lambda (x) (subseq (content-date x) 0 7))
32 32
                         (hash-table-values *content*))))
33 33
     (sort (remove-duplicates months :test #'string=) #'string>)))
34 34
 
@@ -38,23 +38,17 @@
38 38
          (tags (remove-duplicates dupes :test #'string= :key #'tag-slug)))
39 39
     (sort tags #'string< :key #'tag-name)))
40 40
 
41
-(defun get-month (timestamp)
42
-  "Extract the YYYY-MM portion of TIMESTAMP."
43
-  (subseq timestamp 0 7))
44
-
45 41
 (defun index-by-tag (tag content)
46 42
   "Return an index of all CONTENT matching the given TAG."
47
-  (flet ((valid-p (obj) (member tag (content-tags obj) :test #'tag-slug=)))
48
-    (make-instance 'tag-index :id (tag-slug tag)
49
-                   :posts (remove-if-not #'valid-p content)
50
-                   :title (format nil "Posts tagged ~a" (tag-name tag)))))
43
+  (make-instance 'tag-index :id (tag-slug tag)
44
+                 :posts (remove-if-not (lambda (x) (tag-p tag x)) content)
45
+                 :title (format nil "Posts tagged ~a" (tag-name tag))))
51 46
 
52 47
 (defun index-by-month (month content)
53 48
   "Return an index of all CONTENT matching the given MONTH."
54
-  (flet ((valid-p (obj) (search month (content-date obj))))
55
-    (make-instance 'date-index :id month
56
-                               :posts (remove-if-not #'valid-p content)
57
-                               :title (format nil "Posts from ~a" month))))
49
+  (make-instance 'date-index :id month
50
+                 :posts (remove-if-not (lambda (x) (month-p month x)) content)
51
+                 :title (format nil "Posts from ~a" month)))
58 52
 
59 53
 (defun index-by-n (i content &optional (step 10))
60 54
   "Return the index for the Ith page of CONTENT in reverse chronological order."