Commit 5c3d2896 authored by Cheshire Yang's avatar Cheshire Yang
Browse files

Finish basic template rendering

parent 6c7378be
<!doctype html>
<header>Site header</header>
<header>Site Title</header>
Test post please ignore
......@@ -3,7 +3,7 @@
;; Locations for various files
(defparameter *PAGES-DIR* "content/")
(defparameter *LAYOUT-DIR* "layout/")
(defparameter *LAYOUT-DIR* "layout/templates/")
(defparameter *OUTPUT-DIR* "output/")
(defparameter *PRIVATE-KEYS* '(:slug :content))
......@@ -13,19 +13,34 @@
(:slug . "test-page")
(:content . "testpage.html"))))
(defun render-page (page)
((input-path (pathname
(concatenate 'string *PAGES-DIR*
(cdr (assoc :content page)))))
(output-path (pathname
(concatenate 'string *OUTPUT-DIR*
(cdr (assoc :content page)))))
(page-context (remove-if (lambda (p) (find p *PRIVATE-KEYS*)) page :key 'car)))
;; Default template to use unless another is explicitly specified.
(defparameter *DEFAULT-PAGE-TEMPLATE* "primary.html")
(defun make-path (prefix page)
(pathname (concatenate 'string
prefix (cdr (assoc :content page)))))
(defun file-to-string (filepath)
(with-open-file (stream filepath)
(let ((data (make-string (file-length stream))))
(read-sequence data stream)
(defun render-page (page template-path)
((page-path (make-path *PAGES-DIR* page))
(output-path (make-path *OUTPUT-DIR* page))
(page-content (file-to-string page-path))
(page-context (remove-if (lambda (p) (find p *PRIVATE-KEYS*))
(push (cons :page-content page-content) page) :key 'car)))
(with-open-file (output-stream output-path :direction :output
:if-exists :supersede)
(mustache:render input-path page-context output-stream))))
(mustache:render template-path page-context output-stream))))
(defun make-site ()
((template-path (pathname (concatenate 'string *LAYOUT-DIR* *DEFAULT-PAGE-TEMPLATE*))))
(loop for page in *PAGES*
do (render-page page)))
do (render-page page template-path))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment