From 04d9d523d82ebb4ca4889321f8a24a5aafdc1ef3 Mon Sep 17 00:00:00 2001 From: Ralph Moritz Date: Mon, 31 Dec 2012 10:03:41 +0200 Subject: [PATCH] Multi-site support --- example-ccl.post-receive | 9 ----- example.post-receive | 10 ------ examples/example.post-receive | 34 +++++++++++++++++++ examples/multi-site.coleslawrc | 18 ++++++++++ .../single-site.coleslawrc | 0 src/coleslaw.lisp | 7 ++-- src/config.lisp | 25 +++++++++++--- 7 files changed, 77 insertions(+), 26 deletions(-) delete mode 100644 example-ccl.post-receive delete mode 100644 example.post-receive create mode 100644 examples/example.post-receive create mode 100644 examples/multi-site.coleslawrc rename example.coleslawrc => examples/single-site.coleslawrc (100%) diff --git a/example-ccl.post-receive b/example-ccl.post-receive deleted file mode 100644 index 9131a8a..0000000 --- a/example-ccl.post-receive +++ /dev/null @@ -1,9 +0,0 @@ -GIT_REPO=$HOME/lisp-is-fun.git -# TMP_GIT_CLONE _must_ match the :repo arg in coleslawrc excluding trailing slash -TMP_GIT_CLONE=$HOME/lisp-is-fun/tmp - -git clone $GIT_REPO $TMP_GIT_CLONE -echo "(ql:quickload :coleslaw) -(coleslaw:main)" | ccl -b -rm -Rf $TMP_GIT_CLONE -exit diff --git a/example.post-receive b/example.post-receive deleted file mode 100644 index a18ff80..0000000 --- a/example.post-receive +++ /dev/null @@ -1,10 +0,0 @@ -GIT_REPO=$HOME/improvedmeans.git -# TMP_GIT_CLONE _must_ match the :repo arg in coleslawrc excluding trailing slash -TMP_GIT_CLONE=$HOME/tmp/improvedmeans -LISP=sbcl - -git clone $GIT_REPO $TMP_GIT_CLONE -# Only ccl and sbcl support the eval switch, other lisps require a patch here -$LISP --eval "(ql:quickload 'coleslaw)" --eval "(coleslaw:main)" --eval "(trivial-shell:exit)" -rm -Rf $TMP_GIT_CLONE -exit diff --git a/examples/example.post-receive b/examples/example.post-receive new file mode 100644 index 0000000..94eec78 --- /dev/null +++ b/examples/example.post-receive @@ -0,0 +1,34 @@ +########## 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=$HOME/tmp/improvedmeans/ + +# Set LISP to your preferred implementation. The following +# implementations are currently supported: +# * sbcl +# * ccl +LISP=sbcl + +########## DON'T EDIT ANYTHING BELOW THIS LINE ########## + +if cd `dirname "$0"`/..; then + GIT_REPO=`pwd` + cd $OLDPWD || exit 1 +else + exit 1 +fi + +git clone $GIT_REPO $TMP_GIT_CLONE || exit 1 + +if [ $LISP = sbcl ]; then + sbcl --eval "(ql:quickload 'coleslaw)" --eval "(coleslaw:main \"$TMP_GIT_CLONE\")" +elif [ $LISP = ccl ]; then + echo "(ql:quickload 'coleslaw)(coleslaw:main \"$TMP_GIT_CLONE\")" | ccl -b +else + exit 1 +fi + +rm -rf $TMP_GIT_CLONE +exit diff --git a/examples/multi-site.coleslawrc b/examples/multi-site.coleslawrc new file mode 100644 index 0000000..fc01d38 --- /dev/null +++ b/examples/multi-site.coleslawrc @@ -0,0 +1,18 @@ +(("/home/coleslaw/tmp/lisp-is-fun/" . (:author "Ralph Moritz" + :deploy "/home/coleslaw/www/lisp-is-fun/" + :domain "http://blub.co.za" + :feeds ("lisp") + :plugins (mathjax) + :sitenav ((:url "http://twitter.com/ralph_moeritz" :name "Twitter") + (:url "http://github.com/ralph-moeritz" :name "Code")) + :title "(lisp :is 'fun)" + :theme "hyde")) + ("/home/coleslaw/tmp/musings/" . (:author "Ralph Moritz" + :deploy "/home/coleslaw/www/musings/" + :domain "http://musings.co.za" + :feeds ("opinion") + :plugins (mathjax) + :sitenav ((:url "http://twitter.com/ralph_moeritz" :name "Twitter") + (:url "http://github.com/ralph-moeritz" :name "Code")) + :title "Musings" + :theme "hyde"))) diff --git a/example.coleslawrc b/examples/single-site.coleslawrc similarity index 100% rename from example.coleslawrc rename to examples/single-site.coleslawrc diff --git a/src/coleslaw.lisp b/src/coleslaw.lisp index de678e3..ff4476e 100644 --- a/src/coleslaw.lisp +++ b/src/coleslaw.lisp @@ -72,9 +72,10 @@ Additional args to render CONTENT can be passed via RENDER-ARGS." (update-symlink prev (truename curr))) (update-symlink curr new-build))))) -(defun main () - "Load the user's config, then compile and deploy the blog." - (load-config) +(defun main (config-key) + "Load the user's config section corresponding to CONFIG-KEY, then +compile and deploy the blog." + (load-config config-key) (load-posts) (compile-theme (theme *config*)) (compile-blog (staging *config*)) diff --git a/src/config.lisp b/src/config.lisp index c40c811..d2f6cab 100644 --- a/src/config.lisp +++ b/src/config.lisp @@ -13,6 +13,9 @@ (title :initarg :title :initform "" :accessor title) (theme :initarg :theme :initform "hyde" :accessor theme))) +(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.") @@ -35,8 +38,22 @@ are in the plugins folder in coleslaw's source directory." (apply 'enable-plugin (plugin-path name) args))) (symbol (enable-plugin (plugin-path plugin))))))) -(defun load-config (&optional (dir (user-homedir-pathname))) - "Load the coleslaw configuration from DIR/.coleslawrc. DIR is ~ by default." +(defun load-config (config-key &optional (dir (user-homedir-pathname))) + "Load the coleslaw configuration for CONFIG-KEY from DIR/.coleslawrc. DIR is ~ by default." (with-open-file (in (merge-pathnames ".coleslawrc" dir)) - (setf *config* (apply #'make-instance 'blog (read in)))) - (load-plugins (plugins *config*))) + (let ((config-form (read in))) + (if (symbolp (car config-form)) + ;; Single site config: ignore CONFIG-KEY. + (setf *config* (apply #'make-instance '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 #'(lambda (str) (cl-fad:pathname-as-directory str)) + :test #'equal))) + (if section + (progn + (setf *config* (apply #'make-instance 'blog (cdr section))) + (setf (slot-value *config* 'repo) config-key)) + (error 'unknown-config-section-error + :text (format nil "In ~A: No such key: '~A'." in config-key))))) + (load-plugins (plugins *config*)))))