2011-04-16 15:45:37 -04:00
|
|
|
(in-package :coleslaw)
|
|
|
|
|
2012-09-12 10:38:42 -04:00
|
|
|
(defgeneric render (content &key &allow-other-keys)
|
|
|
|
(:documentation "Render the given CONTENT to HTML."))
|
|
|
|
|
|
|
|
(defun render-page (content &optional theme-fn &rest render-args)
|
|
|
|
"Render the given CONTENT to disk using THEME-FN if supplied.
|
|
|
|
Additional args to render CONTENT can be passed via RENDER-ARGS."
|
|
|
|
(let* ((path (etypecase content
|
|
|
|
(post (format nil "posts/~a.html" (post-slug post)))
|
|
|
|
(index (index-path index))))
|
|
|
|
(filepath (merge-pathnames path (staging *config*)))
|
|
|
|
(page (funcall (theme-fn (or theme-fn 'base))
|
|
|
|
(list :config *config*
|
2012-09-12 14:18:23 -04:00
|
|
|
:content content
|
|
|
|
:raw (apply 'render content render-args)
|
|
|
|
:pubdate (make-pubdate)
|
2012-09-12 10:38:42 -04:00
|
|
|
:body-inject (gethash :body *injections*)
|
|
|
|
:head-inject (gethash :head *injections*)))))
|
2012-08-21 19:05:57 -04:00
|
|
|
(ensure-directories-exist filepath)
|
2012-08-21 19:29:43 -04:00
|
|
|
(with-open-file (out filepath
|
2012-09-12 10:38:42 -04:00
|
|
|
:direction :output
|
|
|
|
:if-does-not-exist :create)
|
|
|
|
(write page :stream out))))
|
2012-08-20 11:06:35 -04:00
|
|
|
|
2012-08-27 15:03:34 -04:00
|
|
|
(defun compile-blog (staging)
|
|
|
|
"Compile the blog to a STAGING directory as specified in .coleslawrc."
|
|
|
|
(when (probe-file staging)
|
2012-09-01 00:39:29 +01:00
|
|
|
(run-program "rm -R ~a" staging))
|
2012-08-27 15:03:34 -04:00
|
|
|
(ensure-directories-exist staging)
|
|
|
|
(with-current-directory staging
|
2012-08-29 12:24:08 -04:00
|
|
|
(dolist (dir (list (app-path "themes/~a/css" (theme *config*))
|
|
|
|
(merge-pathnames "static" (repo *config*))))
|
|
|
|
(when (probe-file dir)
|
|
|
|
(run-program "cp -R ~a ." dir)))
|
2012-08-27 15:03:34 -04:00
|
|
|
(render-posts)
|
|
|
|
(render-indices)
|
2012-08-29 23:25:41 -04:00
|
|
|
(render-feeds)))
|
2012-08-20 17:26:12 -04:00
|
|
|
|
2012-08-27 15:03:34 -04:00
|
|
|
(defgeneric deploy (staging)
|
|
|
|
(:documentation "Deploy the STAGING dir, updating the .prev and .curr symlinks.")
|
|
|
|
(:method (staging)
|
2012-08-29 12:50:26 -04:00
|
|
|
(with-current-directory coleslaw-conf:*basedir*
|
|
|
|
(let* ((coleslaw-conf:*basedir* (deploy *config*))
|
|
|
|
(new-build (app-path "generated/~a" (get-universal-time)))
|
|
|
|
(prev (app-path ".prev"))
|
|
|
|
(curr (app-path ".curr")))
|
2012-08-25 15:12:38 -04:00
|
|
|
(ensure-directories-exist new-build)
|
2012-08-29 12:50:26 -04:00
|
|
|
(run-program "mv ~a ~a" staging new-build)
|
2012-08-29 23:48:14 -04:00
|
|
|
(when (probe-file prev)
|
|
|
|
(let ((dest (truename prev)))
|
|
|
|
(if (equal prev dest)
|
|
|
|
(delete-file prev)
|
2012-08-30 00:03:55 -04:00
|
|
|
(run-program "rm -R ~a" dest))))
|
2012-08-29 12:50:26 -04:00
|
|
|
(when (probe-file curr)
|
|
|
|
(update-symlink prev (truename curr)))
|
|
|
|
(update-symlink curr new-build)))))
|
2012-08-19 00:29:33 -04:00
|
|
|
|
2012-08-18 16:40:51 -04:00
|
|
|
(defun main ()
|
2012-08-22 10:05:02 -04:00
|
|
|
"Load the user's config, then compile and deploy the blog."
|
2012-08-18 16:40:51 -04:00
|
|
|
(load-config)
|
2012-09-12 13:37:55 -04:00
|
|
|
(load-posts)
|
2012-09-12 12:52:36 -04:00
|
|
|
(compile-theme (theme *config*))
|
2012-08-27 15:03:34 -04:00
|
|
|
(compile-blog (staging *config*))
|
2012-08-22 10:32:30 -04:00
|
|
|
(deploy (staging *config*)))
|