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-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."
(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 ()
"Compile the blog to a staging directory in /tmp."
(let ((staging (staging *config*)))
; TODO: More incremental compilation? Don't regen whole blog unnecessarily.
2012-08-20 23:20:25 -04:00
(when (probe-file staging)
(delete-directory-and-files staging))
2012-08-20 23:20:25 -04:00
(ensure-directories-exist staging)
(with-current-directory staging
(let ((css-dir (app-path "themes/~a/css" (theme *config*)))
(static-dir (merge-pathnames "static" (repo *config*))))
(dolist (dir (list css-dir static-dir))
(when (probe-file dir)
2012-08-20 23:20:25 -04:00
(run-program "cp" `("-R" ,(namestring dir) ".")))))
(render-posts)
2012-08-21 23:50:36 -04:00
(render-indices)
(render-feed))
(deploy staging)))
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-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)
2012-08-19 14:06:30 -04:00
(compile-theme)
(compile-blog))