Multi-site support

This commit is contained in:
Ralph Moritz 2012-12-31 10:03:41 +02:00
parent 8463a33b62
commit 04d9d523d8
7 changed files with 77 additions and 26 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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