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