2011-04-16 15:45:37 -04:00
|
|
|
(in-package :coleslaw)
|
|
|
|
|
2012-08-22 00:11:33 -04:00
|
|
|
(defun render-page (path html &optional raw)
|
|
|
|
"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."
|
2012-08-21 19:05:57 -04:00
|
|
|
(let ((filepath (merge-pathnames path (staging *config*))))
|
|
|
|
(ensure-directories-exist filepath)
|
2012-08-21 19:29:43 -04:00
|
|
|
(with-open-file (out filepath
|
2012-08-21 19:05:57 -04:00
|
|
|
: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)))))
|
2012-08-20 11:06:35 -04:00
|
|
|
|
2012-08-20 17:26:12 -04:00
|
|
|
(defun compile-blog ()
|
|
|
|
"Compile the blog to a staging directory in /tmp."
|
2012-08-21 19:05:57 -04:00
|
|
|
(let ((staging (staging *config*)))
|
2012-08-20 17:26:12 -04:00
|
|
|
; TODO: More incremental compilation? Don't regen whole blog unnecessarily.
|
2012-08-20 23:20:25 -04:00
|
|
|
(when (probe-file staging)
|
2012-08-21 15:57:01 -04:00
|
|
|
(delete-directory-and-files staging))
|
2012-08-20 23:20:25 -04:00
|
|
|
(ensure-directories-exist staging)
|
2012-08-20 17:26:12 -04:00
|
|
|
(with-current-directory staging
|
2012-08-21 19:05:57 -04:00
|
|
|
(let ((css-dir (app-path "themes/~a/css" (theme *config*)))
|
|
|
|
(static-dir (merge-pathnames "static" (repo *config*))))
|
2012-08-20 17:26:12 -04:00
|
|
|
(dolist (dir (list css-dir static-dir))
|
2012-08-20 20:17:30 -04:00
|
|
|
(when (probe-file dir)
|
2012-08-20 23:20:25 -04:00
|
|
|
(run-program "cp" `("-R" ,(namestring dir) ".")))))
|
2012-08-20 17:26:12 -04:00
|
|
|
(render-posts)
|
2012-08-21 23:50:36 -04:00
|
|
|
(render-indices)
|
|
|
|
(render-feed))
|
2012-08-20 19:43:03 -04:00
|
|
|
(deploy staging)
|
|
|
|
(setf (last-published) (last-commit))))
|
2012-08-20 17:26:12 -04:00
|
|
|
|
2012-08-21 21:43:09 -04:00
|
|
|
(defun update-symlink (path target)
|
|
|
|
"Update the symlink at PATH to point to TARGET."
|
|
|
|
(run-program "ln" (list "-sfn" (namestring target) (namestring path))))
|
2012-08-19 00:48:52 -04:00
|
|
|
|
2012-08-20 19:43:03 -04:00
|
|
|
(defgeneric deploy (dir)
|
|
|
|
(:documentation "Deploy DIR, updating the .prev and .curr symlinks.")
|
|
|
|
(:method (dir)
|
|
|
|
(let ((new-build (app-path "generated/~a" (get-universal-time))))
|
2012-08-21 19:53:31 -04:00
|
|
|
(ensure-directories-exist new-build)
|
2012-08-21 21:43:09 -04:00
|
|
|
(with-current-directory coleslaw-conf:*basedir*
|
|
|
|
(run-program "mv" (mapcar #'namestring (list dir new-build)))
|
|
|
|
(when (probe-file (app-path ".prev"))
|
|
|
|
(delete-directory-and-files (read-symlink (app-path ".prev"))))
|
|
|
|
(when (probe-file (app-path ".curr"))
|
|
|
|
(update-symlink ".prev" (read-symlink (app-path ".curr"))))
|
|
|
|
(update-symlink ".curr" new-build)))))
|
2012-08-19 00:29:33 -04:00
|
|
|
|
2012-08-18 16:40:51 -04:00
|
|
|
(defun main ()
|
|
|
|
(load-config)
|
2012-08-19 14:06:30 -04:00
|
|
|
(compile-theme)
|
2012-08-19 00:29:33 -04:00
|
|
|
(loop do (if (blog-update-p)
|
|
|
|
(compile-blog)
|
|
|
|
(sleep (interval *config*)))))
|