2011-04-16 15:45:37 -04:00
|
|
|
(in-package :coleslaw)
|
|
|
|
|
2012-11-28 16:10:33 -05:00
|
|
|
(defgeneric render (object &key &allow-other-keys)
|
|
|
|
(:documentation "Render the given OBJECT to HTML."))
|
|
|
|
|
|
|
|
(defgeneric render-content (text format)
|
|
|
|
(:documentation "Compile TEXT from the given FORMAT to HTML for display.")
|
|
|
|
(:method (text (format (eql :html)))
|
|
|
|
text)
|
2012-12-11 12:38:54 +02:00
|
|
|
(:method (text (format (eql :md)))
|
2012-11-28 16:10:33 -05:00
|
|
|
(let ((3bmd-code-blocks:*code-blocks* t))
|
|
|
|
(with-output-to-string (str)
|
|
|
|
(3bmd:parse-string-and-print-to-stream text str)))))
|
|
|
|
|
2012-11-28 17:37:19 -05:00
|
|
|
(defgeneric page-path (object)
|
|
|
|
(:documentation "The path to store OBJECT at once rendered."))
|
2012-09-12 10:38:42 -04:00
|
|
|
|
2012-12-14 15:04:21 -05:00
|
|
|
(defmethod page-path :around ((object t))
|
|
|
|
(let ((result (call-next-method)))
|
|
|
|
(if (pathname-type result)
|
2012-12-14 14:55:25 -05:00
|
|
|
result
|
2012-12-14 15:04:21 -05:00
|
|
|
(make-pathname :type "html" :defaults result))))
|
2012-12-14 14:55:25 -05:00
|
|
|
|
2012-09-12 10:38:42 -04:00
|
|
|
(defun render-page (content &optional theme-fn &rest render-args)
|
|
|
|
"Render the given CONTENT to disk using THEME-FN if supplied.
|
|
|
|
Additional args to render CONTENT can be passed via RENDER-ARGS."
|
2013-04-01 11:23:10 -04:00
|
|
|
(funcall (or theme-fn (theme-fn 'base))
|
2012-11-28 16:10:33 -05:00
|
|
|
(list :config *config*
|
|
|
|
:content content
|
|
|
|
:raw (apply 'render content render-args)
|
|
|
|
:pubdate (make-pubdate)
|
|
|
|
:injections (find-injections content))))
|
|
|
|
|
|
|
|
(defun write-page (filepath page)
|
2012-12-14 14:55:25 -05:00
|
|
|
"Write the given PAGE to FILEPATH."
|
|
|
|
(ensure-directories-exist filepath)
|
|
|
|
(with-open-file (out filepath
|
|
|
|
:direction :output
|
2013-04-21 12:13:03 -04:00
|
|
|
:if-exists :supersede
|
2012-12-14 14:55:25 -05:00
|
|
|
:if-does-not-exist :create)
|
|
|
|
(write-line page out)))
|
2012-08-20 11:06:35 -04:00
|
|
|
|
2012-08-27 15:03:34 -04:00
|
|
|
(defun compile-blog (staging)
|
|
|
|
"Compile the blog to a STAGING directory as specified in .coleslawrc."
|
|
|
|
(when (probe-file staging)
|
2012-09-01 00:39:29 +01:00
|
|
|
(run-program "rm -R ~a" staging))
|
2012-08-27 15:03:34 -04:00
|
|
|
(ensure-directories-exist staging)
|
|
|
|
(with-current-directory staging
|
2012-08-29 12:24:08 -04:00
|
|
|
(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)))
|
2013-01-06 15:34:52 -05:00
|
|
|
(do-ctypes (publish ctype))
|
2013-04-21 12:13:03 -04:00
|
|
|
(render-indices)
|
2012-09-12 14:24:51 -04:00
|
|
|
(render-feeds (feeds *config*))))
|
2012-08-20 17:26:12 -04:00
|
|
|
|
2012-08-27 15:03:34 -04:00
|
|
|
(defgeneric deploy (staging)
|
|
|
|
(:documentation "Deploy the STAGING dir, updating the .prev and .curr symlinks.")
|
|
|
|
(:method (staging)
|
2013-04-18 15:53:42 -04:00
|
|
|
(let* ((dest (deploy *config*))
|
|
|
|
(new-build (rel-path dest "generated/~a" (get-universal-time)))
|
|
|
|
(prev (rel-path dest ".prev"))
|
|
|
|
(curr (rel-path dest ".curr")))
|
|
|
|
(ensure-directories-exist new-build)
|
|
|
|
(run-program "mv ~a ~a" staging new-build)
|
|
|
|
(when (probe-file prev)
|
|
|
|
(delete-directory-and-files (truename prev) :if-does-not-exist :ignore))
|
|
|
|
(when (probe-file curr)
|
|
|
|
(update-symlink prev (truename curr)))
|
|
|
|
(update-symlink curr new-build))))
|
2012-08-19 00:29:33 -04:00
|
|
|
|
2012-12-31 10:03:41 +02:00
|
|
|
(defun main (config-key)
|
|
|
|
"Load the user's config section corresponding to CONFIG-KEY, then
|
|
|
|
compile and deploy the blog."
|
2013-04-09 16:36:07 -04:00
|
|
|
(load-config config-key)
|
|
|
|
(load-content)
|
|
|
|
(compile-theme (theme *config*))
|
|
|
|
(compile-blog (staging *config*))
|
|
|
|
(deploy (staging *config*)))
|
2013-04-09 16:23:10 -04:00
|
|
|
|
|
|
|
(defun preview (path &optional (content-type 'post))
|
2013-04-09 16:39:39 -04:00
|
|
|
"Render the content at PATH under user's configured repo and save it to
|
|
|
|
~/tmp.html. Load the user's config and theme if necessary."
|
2013-04-09 16:23:10 -04:00
|
|
|
(unless *config*
|
|
|
|
(load-config nil)
|
|
|
|
(compile-theme (theme *config*)))
|
2013-04-09 16:39:39 -04:00
|
|
|
(let* ((file (rel-path (repo *config*) path))
|
|
|
|
(content (construct content-type (read-content file))))
|
|
|
|
(write-page "~/tmp.html" (render-page content))))
|