Browse Source

Merge pull request #7 from ralph-moeritz/master

Added support for multiple blogs
Brit Butler 12 years ago
parent
commit
ef77026c0c

+ 0 - 9
example-ccl.post-receive

@@ -1,9 +0,0 @@
1
-GIT_REPO=$HOME/lisp-is-fun.git
2
-# TMP_GIT_CLONE _must_ match the :repo arg in coleslawrc excluding trailing slash
3
-TMP_GIT_CLONE=$HOME/lisp-is-fun/tmp
4
-
5
-git clone $GIT_REPO $TMP_GIT_CLONE
6
-echo "(ql:quickload :coleslaw)
7
-(coleslaw:main)" | ccl -b
8
-rm -Rf $TMP_GIT_CLONE
9
-exit

+ 0 - 10
example.post-receive

@@ -1,10 +0,0 @@
1
-GIT_REPO=$HOME/improvedmeans.git
2
-# TMP_GIT_CLONE _must_ match the :repo arg in coleslawrc excluding trailing slash
3
-TMP_GIT_CLONE=$HOME/tmp/improvedmeans
4
-LISP=sbcl
5
-
6
-git clone $GIT_REPO $TMP_GIT_CLONE
7
-# Only ccl and sbcl support the eval switch, other lisps require a patch here
8
-$LISP --eval "(ql:quickload 'coleslaw)" --eval "(coleslaw:main)" --eval "(trivial-shell:exit)"
9
-rm -Rf $TMP_GIT_CLONE
10
-exit

+ 34 - 0
examples/example.post-receive

@@ -0,0 +1,34 @@
1
+########## CONFIGURATION VALUES ##########
2
+
3
+# TMP_GIT_CLONE _must_ match one of the following in coleslawrc: 
4
+#   * The :repo argument (for a single-site setup) _or_
5
+#   * An alist key (for a multi-site setup)
6
+TMP_GIT_CLONE=$HOME/tmp/improvedmeans/
7
+
8
+# Set LISP to your preferred implementation. The following
9
+# implementations are currently supported:
10
+#   * sbcl
11
+#   * ccl
12
+LISP=sbcl
13
+
14
+########## DON'T EDIT ANYTHING BELOW THIS LINE ##########
15
+
16
+if cd `dirname "$0"`/..; then
17
+    GIT_REPO=`pwd`
18
+    cd $OLDPWD || exit 1
19
+else
20
+    exit 1
21
+fi
22
+
23
+git clone $GIT_REPO $TMP_GIT_CLONE || exit 1
24
+
25
+if [ $LISP = sbcl ]; then
26
+    sbcl --eval "(ql:quickload 'coleslaw)" --eval "(coleslaw:main \"$TMP_GIT_CLONE\")"
27
+elif [ $LISP = ccl ]; then
28
+    echo "(ql:quickload 'coleslaw)(coleslaw:main \"$TMP_GIT_CLONE\")" | ccl -b
29
+else
30
+    exit 1
31
+fi
32
+
33
+rm -rf $TMP_GIT_CLONE
34
+exit

+ 18 - 0
examples/multi-site.coleslawrc

@@ -0,0 +1,18 @@
1
+(("/home/coleslaw/tmp/lisp-is-fun/" . (:author "Ralph Moritz"
2
+                                      :deploy "/home/coleslaw/www/lisp-is-fun/"
3
+                                      :domain "http://blub.co.za"
4
+                                      :feeds ("lisp")
5
+                                      :plugins (mathjax)
6
+                                      :sitenav ((:url "http://twitter.com/ralph_moeritz" :name "Twitter")
7
+                                                (:url "http://github.com/ralph-moeritz" :name "Code"))
8
+                                      :title "(lisp :is 'fun)"
9
+                                      :theme "hyde"))
10
+ ("/home/coleslaw/tmp/musings/" . (:author "Ralph Moritz"
11
+                                  :deploy "/home/coleslaw/www/musings/"
12
+                                  :domain "http://musings.co.za"
13
+                                  :feeds ("opinion")
14
+                                  :plugins (mathjax)
15
+                                  :sitenav ((:url "http://twitter.com/ralph_moeritz" :name "Twitter")
16
+                                            (:url "http://github.com/ralph-moeritz" :name "Code"))
17
+                                  :title "Musings"
18
+                                  :theme "hyde")))

example.coleslawrc → examples/single-site.coleslawrc


+ 4 - 3
src/coleslaw.lisp

@@ -72,9 +72,10 @@ Additional args to render CONTENT can be passed via RENDER-ARGS."
72 72
           (update-symlink prev (truename curr)))
73 73
         (update-symlink curr new-build)))))
74 74
 
75
-(defun main ()
76
-  "Load the user's config, then compile and deploy the blog."
77
-  (load-config)
75
+(defun main (config-key)
76
+  "Load the user's config section corresponding to CONFIG-KEY, then
77
+compile and deploy the blog."
78
+  (load-config config-key)
78 79
   (load-posts)
79 80
   (compile-theme (theme *config*))
80 81
   (compile-blog (staging *config*))

+ 21 - 4
src/config.lisp

@@ -13,6 +13,9 @@
13 13
    (title :initarg :title :initform "" :accessor title)
14 14
    (theme :initarg :theme :initform "hyde" :accessor theme)))
15 15
 
16
+(define-condition unknown-config-section-error (error)
17
+  ((text :initarg :text :reader text)))
18
+
16 19
 (defparameter *config* nil
17 20
   "A variable to store the blog configuration and plugin settings.")
18 21
 
@@ -35,8 +38,22 @@ are in the plugins folder in coleslaw's source directory."
35 38
                 (apply 'enable-plugin (plugin-path name) args)))
36 39
         (symbol (enable-plugin (plugin-path plugin)))))))
37 40
 
38
-(defun load-config (&optional (dir (user-homedir-pathname)))
39
-  "Load the coleslaw configuration from DIR/.coleslawrc. DIR is ~ by default."
41
+(defun load-config (config-key &optional (dir (user-homedir-pathname)))
42
+  "Load the coleslaw configuration for CONFIG-KEY from DIR/.coleslawrc. DIR is ~ by default."
40 43
   (with-open-file (in (merge-pathnames ".coleslawrc" dir))
41
-    (setf *config* (apply #'make-instance 'blog (read in))))
42
-  (load-plugins (plugins *config*)))
44
+    (let ((config-form (read in)))
45
+      (if (symbolp (car config-form))
46
+          ;; Single site config: ignore CONFIG-KEY.
47
+          (setf *config* (apply #'make-instance 'blog config-form))
48
+          ;; Multi-site config: load config section for CONFIG-KEY.
49
+          (let* ((config-key-pathname (cl-fad:pathname-as-directory config-key))
50
+                 (section (assoc config-key-pathname config-form
51
+                                 :key #'(lambda (str) (cl-fad:pathname-as-directory str))
52
+                                 :test #'equal)))
53
+            (if section
54
+                (progn 
55
+                  (setf *config* (apply #'make-instance 'blog (cdr section)))
56
+                  (setf (slot-value *config* 'repo) config-key))
57
+                (error 'unknown-config-section-error 
58
+                       :text (format nil "In ~A: No such key: '~A'." in config-key)))))
59
+      (load-plugins (plugins *config*)))))