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-21 19:48:41 -04:00
|
|
|
(defun to-pathname (file &optional (parent coleslaw-conf:*basedir*))
|
2012-08-20 09:41:50 -04:00
|
|
|
"Convert an iolib file-path back to a pathname."
|
|
|
|
(merge-pathnames (file-path-namestring file) parent))
|
|
|
|
|
2012-08-21 19:48:41 -04:00
|
|
|
(defun read-symlink (path)
|
|
|
|
"A trivial wrapper over iolib.os that returns the pathname in the symlink PATH."
|
|
|
|
(to-pathname (iolib.os:read-symlink path)))
|
|
|
|
|
2012-08-20 10:44:46 -04:00
|
|
|
(defmacro do-files ((var path &optional extension) &body body)
|
|
|
|
"For each file under PATH, run BODY. If EXTENSION is provided, only run BODY
|
|
|
|
on files that match the given extension."
|
|
|
|
(alexandria:with-gensyms (ext)
|
2012-08-21 15:57:01 -04:00
|
|
|
`(mapcar (lambda (,var)
|
|
|
|
,@(if extension
|
|
|
|
`((let ((,ext (pathname-type ,var)))
|
|
|
|
(when (and ,ext (string= ,ext ,extension))
|
|
|
|
,@body)))
|
|
|
|
`,body))
|
|
|
|
(list-directory ,path))))
|
2012-08-20 09:41:50 -04:00
|
|
|
|
2012-08-20 11:06:35 -04:00
|
|
|
(defun render-page (path html)
|
2012-08-20 17:26:12 -04:00
|
|
|
"Populate the base template with the provided HTML and write it out to PATH."
|
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*)))))
|
|
|
|
(write-line 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*)))))
|