coleslaw/src/coleslaw.lisp

64 lines
2.8 KiB
Common Lisp
Raw Normal View History

2011-04-16 15:45:37 -04:00
(in-package :coleslaw)
2012-08-29 13:37:59 -04:00
(defun render-page (path html &key raw)
2012-08-22 00:11:33 -04:00
"Populate the base template with the provided HTML and write it out to PATH.
If RAW is non-nil, write the content without wrapping it in the base template."
(let ((filepath (merge-pathnames path (staging *config*))))
(ensure-directories-exist filepath)
2012-08-21 19:29:43 -04:00
(with-open-file (out filepath
:direction :output
:if-does-not-exist :create)
(let ((content (funcall (theme-fn 'base)
(list :title (title *config*)
:siteroot (domain *config*)
:navigation (sitenav *config*)
:content html
:head-inject (apply #'concatenate 'string
(gethash :head *injections*))
:body-inject (apply #'concatenate 'string
(gethash :body *injections*))
:license (license *config*)
:credits (author *config*)))))
2012-08-22 00:11:33 -04:00
(write-line (if raw html content) out)))))
(defun compile-blog (staging)
"Compile the blog to a STAGING directory as specified in .coleslawrc."
; TODO: More incremental compilation? Don't regen whole blog unnecessarily.
(when (probe-file staging)
(run-program "rm -R ~a" staging))
(ensure-directories-exist staging)
(with-current-directory staging
(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)))
(render-posts)
(render-indices)
2012-08-29 23:25:41 -04:00
(render-feeds)))
(defgeneric deploy (staging)
(:documentation "Deploy the STAGING dir, updating the .prev and .curr symlinks.")
(:method (staging)
(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")))
(ensure-directories-exist new-build)
(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)
(run-program "rm -R ~a" dest))))
(when (probe-file curr)
(update-symlink prev (truename curr)))
(update-symlink curr new-build)))))
2012-08-18 16:40:51 -04:00
(defun main ()
"Load the user's config, then compile and deploy the blog."
2012-08-18 16:40:51 -04:00
(load-config)
(compile-theme)
(compile-blog (staging *config*))
2012-08-22 10:32:30 -04:00
(deploy (staging *config*)))