Преглед на файлове

Simplify the support for multi-site configs.

Brit Butler преди 11 години
родител
ревизия
a9740474eb
променени са 5 файла, в които са добавени 22 реда и са изтрити 43 реда
  1. 8 3
      NEWS.md
  2. 0 9
      docs/hacking.md
  3. 1 3
      examples/example.post-receive
  4. 2 2
      src/coleslaw.lisp
  5. 11 26
      src/config.lisp

+ 8 - 3
NEWS.md

@@ -2,9 +2,14 @@
2 2
 
3 3
 * **SITE-BREAKING CHANGE**: Coleslaw now supports user-defined routing.
4 4
   Instead of hard-coding the paths various content types are stored at,
5
-  they must be specified in the configuration file (.coleslawrc). Just
6
-  copy the `:routing` key from the [example][single_site.rc] to get
7
-  the old behavior.
5
+  they **must** be specified in the configuration file (.coleslawrc).
6
+  Just copy the `:routing` key from the [example][single_site.rc] to
7
+  get the old behavior.
8
+* **SITE-BREAKING CHANGE**: Coleslaw's multi-site support has changed.
9
+  Instead of having a single .coleslawrc in the user's home directory
10
+  that has sections for multiple repos, a .coleslawrc may be included
11
+  *in* the blog repo itself. If no .coleslawrc is found in the repo,
12
+  it is loaded from the user's home directory instead.
8 13
 * Coleslaw no longer expects a particular repo layout. Use whatever
9 14
   directory hierarchy you like.
10 15
 * New Content Type Plugin: Static Pages, accepting a title, url, and

+ 0 - 9
docs/hacking.md

@@ -168,15 +168,6 @@ freshly built site.
168 168
 
169 169
 ## Areas for Improvement
170 170
 
171
-### Simplify Config Handling?
172
-
173
-Right now we expect .coleslawrc to be in the user's home directory by
174
-default. It would be interesting if we expected the .coleslawrc to be
175
-in the blog repo instead. Each blog would be responsible for its own
176
-configuration so we could simplify `load-config` drastically. Finally,
177
-we could check for the config in the home directory as a last option
178
-to remain backwards compatible.
179
-
180 171
 ### New Content Type: Shouts!
181 172
 
182 173
 I've also toyed with the idea of a content type called a SHOUT, which

+ 1 - 3
examples/example.post-receive

@@ -1,8 +1,6 @@
1 1
 ########## CONFIGURATION VALUES ##########
2 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)
3
+# TMP_GIT_CLONE _must_ match the :repo argument in your .coleslawrc!
6 4
 TMP_GIT_CLONE=$HOME/tmp/improvedmeans/
7 5
 
8 6
 # Set LISP to your preferred implementation. The following

+ 2 - 2
src/coleslaw.lisp

@@ -1,8 +1,8 @@
1 1
 (in-package :coleslaw)
2 2
 
3
-(defun main (&optional (config-key ""))
3
+(defun main (&optional (repo-dir ""))
4 4
   "Load the user's config file, then compile and deploy the site."
5
-  (load-config config-key)
5
+  (load-config repo-dir)
6 6
   (load-content)
7 7
   (compile-theme (theme *config*))
8 8
   (let ((dir (staging-dir *config*)))

+ 11 - 26
src/config.lisp

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