From a9740474eb21aa58f7d56fb8e85e17355e4e2eed Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Fri, 2 May 2014 15:03:15 -0400 Subject: [PATCH] Simplify the support for multi-site configs. --- NEWS.md | 11 ++++++++--- docs/hacking.md | 9 --------- examples/example.post-receive | 4 +--- src/coleslaw.lisp | 4 ++-- src/config.lisp | 37 +++++++++++------------------------ 5 files changed, 22 insertions(+), 43 deletions(-) diff --git a/NEWS.md b/NEWS.md index c42eb17..014005a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,9 +2,14 @@ * **SITE-BREAKING CHANGE**: Coleslaw now supports user-defined routing. Instead of hard-coding the paths various content types are stored at, - they must be specified in the configuration file (.coleslawrc). Just - copy the `:routing` key from the [example][single_site.rc] to get - the old behavior. + they **must** be specified in the configuration file (.coleslawrc). + Just copy the `:routing` key from the [example][single_site.rc] to + get the old behavior. +* **SITE-BREAKING CHANGE**: Coleslaw's multi-site support has changed. + Instead of having a single .coleslawrc in the user's home directory + that has sections for multiple repos, a .coleslawrc may be included + *in* the blog repo itself. If no .coleslawrc is found in the repo, + it is loaded from the user's home directory instead. * Coleslaw no longer expects a particular repo layout. Use whatever directory hierarchy you like. * New Content Type Plugin: Static Pages, accepting a title, url, and diff --git a/docs/hacking.md b/docs/hacking.md index e88caf3..f8adae3 100644 --- a/docs/hacking.md +++ b/docs/hacking.md @@ -168,15 +168,6 @@ freshly built site. ## Areas for Improvement -### Simplify Config Handling? - -Right now we expect .coleslawrc to be in the user's home directory by -default. It would be interesting if we expected the .coleslawrc to be -in the blog repo instead. Each blog would be responsible for its own -configuration so we could simplify `load-config` drastically. Finally, -we could check for the config in the home directory as a last option -to remain backwards compatible. - ### New Content Type: Shouts! I've also toyed with the idea of a content type called a SHOUT, which diff --git a/examples/example.post-receive b/examples/example.post-receive index 7552c57..78fd288 100644 --- a/examples/example.post-receive +++ b/examples/example.post-receive @@ -1,8 +1,6 @@ ########## CONFIGURATION VALUES ########## -# TMP_GIT_CLONE _must_ match one of the following in coleslawrc: -# * The :repo argument (for a single-site setup) _or_ -# * An alist key (for a multi-site setup) +# TMP_GIT_CLONE _must_ match the :repo argument in your .coleslawrc! TMP_GIT_CLONE=$HOME/tmp/improvedmeans/ # Set LISP to your preferred implementation. The following diff --git a/src/coleslaw.lisp b/src/coleslaw.lisp index 97add61..b147f31 100644 --- a/src/coleslaw.lisp +++ b/src/coleslaw.lisp @@ -1,8 +1,8 @@ (in-package :coleslaw) -(defun main (&optional (config-key "")) +(defun main (&optional (repo-dir "")) "Load the user's config file, then compile and deploy the site." - (load-config config-key) + (load-config repo-dir) (load-content) (compile-theme (theme *config*)) (let ((dir (staging-dir *config*))) diff --git a/src/config.lisp b/src/config.lisp index 7f91651..4b201ad 100644 --- a/src/config.lisp +++ b/src/config.lisp @@ -16,9 +16,6 @@ (theme :initarg :theme :accessor theme) (title :initarg :title :accessor title))) -(define-condition unknown-config-section-error (error) - ((text :initarg :text :reader text))) - (defparameter *config* nil "A variable to store the blog configuration and plugin settings.") @@ -40,30 +37,18 @@ are in the plugins folder in coleslaw's source directory." (destructuring-bind (name &rest args) plugin (apply 'enable-plugin (plugin-path name) args))))) -(defun discover-config-path (path) - "Check the supplied PATH for a .coleslawrc and if one +(defun discover-config-path (repo-path) + "Check the supplied REPO-PATH for a .coleslawrc and if one doesn't exist, use the .coleslawrc in the home directory." - (let ((custom-path (rel-path path ".coleslawrc"))) - (if (file-exists-p custom-path) - custom-path + (let ((repo-config (rel-path repo-path ".coleslawrc"))) + (if (file-exists-p repo-config) + repo-config (rel-path (user-homedir-pathname) ".coleslawrc")))) -(defun load-config (&optional config-key) - "Load the coleslaw configuration from DIR/.coleslawrc, using CONFIG-KEY -if necessary. DIR is ~ by default." - (with-open-file (in (discover-config-path config-key) :external-format '(:utf-8)) +(defun load-config (&optional repo-dir) + "Find and load the coleslaw configuration from .coleslawrc. REPO-DIR will be +preferred over the home directory if provided." + (with-open-file (in (discover-config-path repo-dir) :external-format '(:utf-8)) (let ((config-form (read in))) - (if (symbolp (car config-form)) - ;; Single site config: ignore CONFIG-KEY. - (setf *config* (construct 'blog config-form)) - ;; Multi-site config: load config section for CONFIG-KEY. - (let* ((config-key-pathname (cl-fad:pathname-as-directory config-key)) - (section (assoc config-key-pathname config-form - :key #'cl-fad:pathname-as-directory - :test #'equal))) - (if section - (setf *config* (construct 'blog (cdr section)) - (repo *config*) config-key) - (error 'unknown-config-section-error - :text (format nil "In ~A: No such key: '~A'." in config-key))))) - (load-plugins (plugins *config*))))) + (setf *config* (construct 'blog config-form)))) + (load-plugins (plugins *config*)))