From 939c0be318e1c5b643064a8fc8c014216e4e7357 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Wed, 12 Sep 2012 10:38:42 -0400 Subject: [PATCH] Overhaul RENDER-PAGE. --- src/coleslaw.lisp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/coleslaw.lisp b/src/coleslaw.lisp index a6e84ad..f09121e 100644 --- a/src/coleslaw.lisp +++ b/src/coleslaw.lisp @@ -1,29 +1,28 @@ (in-package :coleslaw) -(defun render-page (path html &key 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*)))) +(defgeneric render (content &key &allow-other-keys) + (:documentation "Render the given CONTENT to HTML.")) + +(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." + (let* ((path (etypecase content + (post (format nil "posts/~a.html" (post-slug post))) + (index (index-path index)))) + (filepath (merge-pathnames path (staging *config*))) + (page (funcall (theme-fn (or theme-fn 'base)) + (list :config *config* + :content (apply 'render content render-args) + :body-inject (gethash :body *injections*) + :head-inject (gethash :head *injections*))))) (ensure-directories-exist filepath) (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*))))) - (write-line (if raw html content) out))))) + :direction :output + :if-does-not-exist :create) + (write page :stream out)))) (defun compile-blog (staging) "Compile the blog to a STAGING directory as specified in .coleslawrc." - ; TODO: More incremental compilation? Don't regen whole blog unnecessarily. (when (probe-file staging) (run-program "rm -R ~a" staging)) (ensure-directories-exist staging)