|
@@ -16,9 +16,6 @@
|
16
|
16
|
(theme :initarg :theme :accessor theme)
|
17
|
17
|
(title :initarg :title :accessor title)))
|
18
|
18
|
|
19
|
|
-(define-condition unknown-config-section-error (error)
|
20
|
|
- ((text :initarg :text :reader text)))
|
21
|
|
-
|
22
|
19
|
(defparameter *config* nil
|
23
|
20
|
"A variable to store the blog configuration and plugin settings.")
|
24
|
21
|
|
|
@@ -40,30 +37,18 @@ are in the plugins folder in coleslaw's source directory."
|
40
|
37
|
(destructuring-bind (name &rest args) plugin
|
41
|
38
|
(apply 'enable-plugin (plugin-path name) args)))))
|
42
|
39
|
|
43
|
|
-(defun discover-config-path (path)
|
44
|
|
- "Check the supplied PATH for a .coleslawrc and if one
|
|
40
|
+(defun discover-config-path (repo-path)
|
|
41
|
+ "Check the supplied REPO-PATH for a .coleslawrc and if one
|
45
|
42
|
doesn't exist, use the .coleslawrc in the home directory."
|
46
|
|
- (let ((custom-path (rel-path path ".coleslawrc")))
|
47
|
|
- (if (file-exists-p custom-path)
|
48
|
|
- custom-path
|
|
43
|
+ (let ((repo-config (rel-path repo-path ".coleslawrc")))
|
|
44
|
+ (if (file-exists-p repo-config)
|
|
45
|
+ repo-config
|
49
|
46
|
(rel-path (user-homedir-pathname) ".coleslawrc"))))
|
50
|
47
|
|
51
|
|
-(defun load-config (&optional config-key)
|
52
|
|
- "Load the coleslaw configuration from DIR/.coleslawrc, using CONFIG-KEY
|
53
|
|
-if necessary. DIR is ~ by default."
|
54
|
|
- (with-open-file (in (discover-config-path config-key) :external-format '(:utf-8))
|
|
48
|
+(defun load-config (&optional repo-dir)
|
|
49
|
+ "Find and load the coleslaw configuration from .coleslawrc. REPO-DIR will be
|
|
50
|
+preferred over the home directory if provided."
|
|
51
|
+ (with-open-file (in (discover-config-path repo-dir) :external-format '(:utf-8))
|
55
|
52
|
(let ((config-form (read in)))
|
56
|
|
- (if (symbolp (car config-form))
|
57
|
|
- ;; Single site config: ignore CONFIG-KEY.
|
58
|
|
- (setf *config* (construct 'blog config-form))
|
59
|
|
- ;; Multi-site config: load config section for CONFIG-KEY.
|
60
|
|
- (let* ((config-key-pathname (cl-fad:pathname-as-directory config-key))
|
61
|
|
- (section (assoc config-key-pathname config-form
|
62
|
|
- :key #'cl-fad:pathname-as-directory
|
63
|
|
- :test #'equal)))
|
64
|
|
- (if section
|
65
|
|
- (setf *config* (construct 'blog (cdr section))
|
66
|
|
- (repo *config*) config-key)
|
67
|
|
- (error 'unknown-config-section-error
|
68
|
|
- :text (format nil "In ~A: No such key: '~A'." in config-key)))))
|
69
|
|
- (load-plugins (plugins *config*)))))
|
|
53
|
+ (setf *config* (construct 'blog config-form))))
|
|
54
|
+ (load-plugins (plugins *config*)))
|