Bladeren bron

Hey, look! User-defined routes are easy. Slot-value is gross though.

Brit Butler 11 jaren geleden
bovenliggende
commit
f56270430f
3 gewijzigde bestanden met toevoegingen van 25 en 1 verwijderingen
  1. 12 0
      examples/multi-site.coleslawrc
  2. 6 0
      examples/single-site.coleslawrc
  3. 7 1
      src/documents.lisp

+ 12 - 0
examples/multi-site.coleslawrc

@@ -3,6 +3,12 @@
3 3
                                       :domain "http://blub.co.za"
4 4
                                       :feeds ("lisp")
5 5
                                       :plugins ((mathjax))
6
+                                      :routing ((:post           "posts/~a")
7
+                                                (:tag-index      "tag/~a")
8
+                                                (:month-index    "date/~a")
9
+                                                (:numeric-index  "~d")
10
+                                                (:feed           "~a.xml")
11
+                                                (:tag-feed       "tag/~a.xml"))
6 12
                                       :sitenav ((:url "http://twitter.com/ralph_moeritz" :name "Twitter")
7 13
                                                 (:url "http://github.com/ralph-moeritz" :name "Code"))
8 14
                                       :staging-dir "/tmp/coleslaw"
@@ -13,6 +19,12 @@
13 19
                                   :domain "http://musings.co.za"
14 20
                                   :feeds ("opinion")
15 21
                                   :plugins ((mathjax))
22
+                                  :routing ((:post           "posts/~a")
23
+                                            (:tag-index      "tag/~a")
24
+                                            (:month-index    "date/~a")
25
+                                            (:numeric-index  "~d")
26
+                                            (:feed           "~a.xml")
27
+                                            (:tag-feed       "tag/~a.xml"))
16 28
                                   :sitenav ((:url "http://twitter.com/ralph_moeritz" :name "Twitter")
17 29
                                             (:url "http://github.com/ralph-moeritz" :name "Code"))
18 30
                                   :staging-dir "/tmp/coleslaw"

+ 6 - 0
examples/single-site.coleslawrc

@@ -7,6 +7,12 @@
7 7
            (disqus :shortname "my-site-name")
8 8
            (analytics :tracking-code "foo"))
9 9
  :repo "/home/git/tmp/improvedmeans/"
10
+ :routing ((:post           "posts/~a")
11
+           (:tag-index      "tag/~a")
12
+           (:month-index    "date/~a")
13
+           (:numeric-index  "~d")
14
+           (:feed           "~a.xml")
15
+           (:tag-feed       "tag/~a.xml"))
10 16
  :sitenav ((:url "http://redlinernotes.com/" :name "Home")
11 17
            (:url "http://twitter.com/redline6561" :name "Twitter")
12 18
            (:url "http://github.com/redline6561" :name "Code")

+ 7 - 1
src/documents.lisp

@@ -27,7 +27,13 @@
27 27
 ;; Instance Methods
28 28
 
29 29
 (defgeneric page-url (document)
30
-  (:documentation "The url to the DOCUMENT without the domain."))
30
+  (:documentation "The url to the DOCUMENT without the domain.")
31
+  (:method (document)
32
+    (let* ((class-name (class-name (class-of document)))
33
+           (route (assoc class-name (routing *config*))))
34
+      (if route
35
+          (format nil (second route) (slot-value document 'slug))
36
+          (error "No routing method found for: ~A" class-name)))))
31 37
 
32 38
 (defmethod page-url :around ((document t))
33 39
   (let ((result (call-next-method)))