Make sure we render off the base template.

This commit is contained in:
Brit Butler 2012-08-20 11:06:35 -04:00
parent d571634677
commit b92fb4d9b6
3 changed files with 34 additions and 15 deletions

View file

@ -36,6 +36,24 @@ on files that match the given extension."
(render-indices)) (render-indices))
(deploy staging))) (deploy staging)))
(defun render-page (path html)
(ensure-directories-exist path)
(with-open-file (out path
: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 content out))))
(defun update-symlink (name target) (defun update-symlink (name target)
"Update the symlink NAME to point to TARGET." "Update the symlink NAME to point to TARGET."
(run-program "ln" (list "-sfn" (namestring target) name))) (run-program "ln" (list "-sfn" (namestring target) name)))

View file

@ -1,6 +1,6 @@
(in-package :coleslaw) (in-package :coleslaw)
(defparameter *metadata* (make-hash-table :test #'equal)) (defparameter *posts* (make-hash-table :test #'equal))
(defclass post () (defclass post ()
((slug :initform nil :initarg :slug :accessor post-slug) ((slug :initform nil :initarg :slug :accessor post-slug)
@ -15,24 +15,22 @@
(do-files (file (repo *config*) "post") (do-files (file (repo *config*) "post")
(with-open-file (in file) (with-open-file (in file)
(let ((post (read-post in))) (let ((post (read-post in)))
(setf (gethash (post-slug post) *metadata*) post)))) (setf (gethash (post-slug post) *posts*) post))))
(maphash #'write-post *metadata*)) (maphash #'write-post *posts*))
(defun read-post (stream) (defun read-post (stream)
"Make a POST instance based on the data from STREAM." "Make a POST instance based on the data from STREAM."
(make-instance 'post
:slug (make-slug post))
) )
(defun write-post (slug post) (defun write-post (slug post)
"Write out the HTML for POST in SLUG.html." "Write out the HTML for POST in SLUG.html."
(with-open-file (out (format nil "~a.html" slug) (render-page (format nil "~a.html" slug)
:direction :output (funcall (theme-fn "POST")
:if-does-not-exist :create) (list :title (post-title post)
(let ((content (funcall (theme-fn "POST") :tags (post-tags post)
(list :title (post-title post) :date (post-date post)
:tags (post-tags post) :content (post-content post)
:date (post-date post) :prev nil
:content (post-content post) :next nil))))
:prev nil
:next nil))))
(write content out))))

View file

@ -16,6 +16,9 @@
(defun theme-package (&key (name (theme *config*))) (defun theme-package (&key (name (theme *config*)))
(find-package (string-upcase (concatenate 'string "coleslaw.theme." name)))) (find-package (string-upcase (concatenate 'string "coleslaw.theme." name))))
(defun theme-fn (name)
(find-symbol name (theme-package)))
(defun compile-theme (&key (theme-dir (app-path "themes/~a/" (theme *config*)))) (defun compile-theme (&key (theme-dir (app-path "themes/~a/" (theme *config*))))
(do-files (file theme-dir "tmpl") (do-files (file theme-dir "tmpl")
(compile-template :common-lisp-backend file))) (compile-template :common-lisp-backend file)))