Brit Butler преди 13 години
родител
ревизия
0326e6ff2e
променени са 4 файла, в които са добавени 26 реда и са изтрити 16 реда
  1. 1 1
      TODO
  2. 3 3
      coleslaw.asd
  3. 7 6
      src/indices.lisp
  4. 15 6
      src/posts.lisp

+ 1 - 1
TODO

@@ -13,7 +13,7 @@ Plugins? Injection support for HEAD and BODY. What about predicate-based injecti
13 13
 How is it served? Hunchentoot, Lighttpd, S3, whomever!
14 14
 
15 15
 TODO:
16
-; blockers to use this for redlinernotes: prev/next, rss/atom feed, markdown support
16
+; blockers to use this for redlinernotes: rss/atom feed, markdown support
17 17
 ; after that, focus on injections for code highlighting and latex
18 18
 
19 19
 ; doc themes and plugins

+ 3 - 3
coleslaw.asd

@@ -10,11 +10,11 @@
10 10
   :components ((:file "packages")
11 11
                (:file "config")
12 12
                (:file "git")
13
-               (:file "coleslaw")
14 13
                (:file "themes")
14
+               (:file "plugins")
15
+               (:file "coleslaw")
15 16
                (:file "posts")
16
-               (:file "indices")
17
-               (:file "plugins"))
17
+               (:file "indices"))
18 18
   :in-order-to ((test-op (load-op coleslaw-tests)))
19 19
   :perform (test-op :after (op c)
20 20
                     (funcall (intern "RUN!" :coleslaw-tests)

+ 7 - 6
src/indices.lisp

@@ -30,7 +30,7 @@
30 30
   "Sort POSTS in reverse chronological order."
31 31
   (sort posts #'string> :key #'post-date))
32 32
 
33
-(defun write-index (posts filename title)
33
+(defun write-index (posts filename title &optional prev next)
34 34
   "Write out the HTML for POSTS to FILENAME.html."
35 35
   (let ((content (loop for post in posts
36 36
                     collect (list :url (format nil "~a/posts/~a.html"
@@ -45,18 +45,19 @@
45 45
                                 :monthlinks (monthlinks)
46 46
                                 :title title
47 47
                                 :posts content
48
-                                ; TODO: Populate prev and next with links.
49
-                                :prev nil
50
-                                :next nil)))))
48
+                                :prev (and prev (format nil "~d.html" prev))
49
+                                :next (and next (format nil "~d.html" next)))))))
51 50
 
52 51
 (defun render-by-20 ()
53 52
   "Render the indices to view posts in reverse chronological order by 20."
54 53
   (flet ((by-20 (posts start)
55 54
            (let ((index (* 20 (1- start))))
56 55
              (subseq posts index (min (length posts) (+ index 20))))))
57
-    (let ((posts (by-date (hash-table-value *posts*))))
56
+    (let ((posts (by-date (hash-table-values *posts*))))
58 57
       (loop for i = 1 then (1+ i)
59
-         do (write-index (by-20 posts i) (format nil "~d.html" i) "Recent Posts")
58
+         do (write-index (by-20 posts i) (format nil "~d.html" i) "Recent Posts"
59
+                         (and (plusp (1- i)) (1- i))
60
+                         (and (< (* i 20) (length posts)) (1+ i)))
60 61
          until (> (* i 20) (length posts))))))
61 62
 
62 63
 (defun render-by-tag ()

+ 15 - 6
src/posts.lisp

@@ -22,10 +22,20 @@
22 22
                    (post-slug post))
23 23
             (setf (gethash (post-slug post) *posts*) post))))))
24 24
 
25
+(defun post-url (post)
26
+  "Return the relative URL for a given post."
27
+  (format nil "posts/~a.html" (post-slug post)))
28
+
25 29
 (defun render-posts ()
26 30
   "Iterate through the files in the repo to render+write the posts out to disk."
27 31
   (load-posts)
28
-  (maphash #'write-post *posts*))
32
+  (loop with posts = (sort (hash-table-values *posts*) #'string< :key #'post-date)
33
+     for i from 1 upto (length posts)
34
+     for prev = nil then post
35
+     for post = (nth (1- i) posts)
36
+     for next = (nth (1+ i) posts)
37
+     do (write-post post :prev (and prev (post-url prev))
38
+                         :next (and next (post-url next)))))
29 39
 
30 40
 (defgeneric render-content (text format)
31 41
   (:documentation "Compile TEXT from the given FORMAT to HTML for display.")
@@ -51,18 +61,17 @@
51 61
            (append args (list :content (read-line in nil)
52 62
                               :slug (slugify (getf args :title))))))))
53 63
 
54
-(defun write-post (slug post)
64
+(defun write-post (post &key prev next)
55 65
   "Write out the HTML for POST in SLUG.html."
56
-  (render-page (format nil "posts/~a.html" slug)
66
+  (render-page (post-url post)
57 67
                (funcall (theme-fn "POST")
58 68
                         (list :title (post-title post)
59 69
                               :tags (post-tags post)
60 70
                               :date (post-date post)
61 71
                               :content (render-content (post-content post)
62 72
                                                        (post-format post))
63
-                              ; TODO: Populate prev and next with links.
64
-                              :prev nil
65
-                              :next nil))))
73
+                              :prev prev
74
+                              :next next))))
66 75
 
67 76
 (defun slug-char-p (char)
68 77
   "Determine if CHAR is a valid slug (i.e. URL) character."