Simplify the support for multi-site configs.

This commit is contained in:
Brit Butler 2014-05-02 15:03:15 -04:00
parent a03962f7f8
commit a9740474eb
5 changed files with 22 additions and 43 deletions

11
NEWS.md
View file

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

View file

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

View file

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

View file

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

View file

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