2011-04-16 15:45:37 -04:00
|
|
|
(in-package :coleslaw)
|
|
|
|
|
2012-08-19 14:06:30 -04:00
|
|
|
(defun app-path (path &rest args)
|
|
|
|
"Take a relative PATH and return the corresponding pathname beneath coleslaw.
|
|
|
|
If ARGS is provided, use (apply 'format nil PATH ARGS) as the value of PATH."
|
|
|
|
(merge-pathnames (apply 'format nil path args) coleslaw-conf:*basedir*))
|
2012-08-18 16:40:51 -04:00
|
|
|
|
2012-08-20 09:41:50 -04:00
|
|
|
(defun to-pathname (file parent)
|
|
|
|
"Convert an iolib file-path back to a pathname."
|
|
|
|
(merge-pathnames (file-path-namestring file) parent))
|
|
|
|
|
|
|
|
(defmacro do-files ((var path) &body body)
|
|
|
|
"For each file under PATH, run BODY."
|
|
|
|
`(iolib.os:mapdir (lambda (x)
|
|
|
|
(let ((,var (to-pathname x ,path)))
|
|
|
|
,@body)) ,path))
|
|
|
|
|
2012-08-18 16:40:51 -04:00
|
|
|
(defun compile-blog ()
|
2012-08-18 23:00:33 -04:00
|
|
|
(let ((staging #p"/tmp/coleslaw/"))
|
|
|
|
; TODO: More incremental compilation? Don't regen whole blog unnecessarily.
|
|
|
|
(if (probe-file staging)
|
2012-08-19 00:29:33 -04:00
|
|
|
(delete-files staging :recursive t)
|
2012-08-18 23:00:33 -04:00
|
|
|
(ensure-directories-exist staging))
|
|
|
|
(with-current-directory staging
|
2012-08-19 14:06:30 -04:00
|
|
|
(let ((css-dir (app-path "themes/~a/css/" (theme *config*)))
|
2012-08-18 23:00:33 -04:00
|
|
|
(static-dir (merge-pathnames "static/" (repo *config*))))
|
|
|
|
(dolist (dir (list css-dir static-dir))
|
2012-08-19 00:29:33 -04:00
|
|
|
(run-program "cp" `("-R" ,dir "."))))
|
2012-08-18 23:00:33 -04:00
|
|
|
(render-posts)
|
|
|
|
(render-indices))
|
|
|
|
(deploy staging)))
|
2012-08-18 16:40:51 -04:00
|
|
|
|
2012-08-19 00:48:52 -04:00
|
|
|
(defun update-symlink (name target)
|
|
|
|
"Update the symlink NAME to point to TARGET."
|
|
|
|
(run-program "ln" (list "-sfn" (namestring target) name)))
|
|
|
|
|
2012-08-19 00:29:33 -04:00
|
|
|
(defun deploy (dir)
|
|
|
|
"Deploy DIR, updating the .prev and .curr symlinks."
|
2012-08-19 14:06:30 -04:00
|
|
|
(let ((new-build (app-path "generated/~a" (get-universal-time))))
|
2012-08-19 00:48:52 -04:00
|
|
|
(run-program "mv" (list dir (namestring new-build)))
|
2012-08-19 00:29:33 -04:00
|
|
|
(when (probe-file (app-path ".prev"))
|
|
|
|
(delete-files (read-symlink (app-path ".prev")) :recursive t))
|
|
|
|
(when (probe-file (app-path ".curr"))
|
2012-08-19 00:48:52 -04:00
|
|
|
(update-symlink ".prev" (read-symlink (app-path ".curr"))))
|
|
|
|
(update-symlink ".curr" new-build))
|
2012-08-19 00:29:33 -04:00
|
|
|
(setf (last-published) (last-commit)))
|
|
|
|
|
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*)))))
|