process.lisp 1.9 KB
Newer Older
Cherie Yang's avatar
Cherie Yang committed
1 2 3 4
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(in-package :cl-site)

;; Copies/renders stylesheets + adds to global context
5 6 7 8 9 10 11 12 13
(defun process-styles () 
  (let 
      ((styles-list (mapcar 
		     (lambda (s) (progn
				   (uiop:copy-file (make-path *STYLES-DIR* s)
						   (make-path *OUTPUT-DIR* s))
				   (cons :location s)))
		     *STYLES*))) 
    (push (cons :styles styles-list) *GLOBAL-CONTEXT*)))
Cherie Yang's avatar
Cherie Yang committed
14

Cherie Yang's avatar
Cherie Yang committed
15 16
;; Copies/renders script files + adds to global context
(defun process-scripts () nil)
Cherie Yang's avatar
Cherie Yang committed
17

Cherie Yang's avatar
Cherie Yang committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
;; Copies/renders static assets (imgs, etc)
(defun process-static () 
  (let* 
      ((static-output-dir (merge-pathnames #P"static/" *OUTPUT-DIR*))
       (static-list (mapcar 
		     (lambda (s) (progn
				   (uiop:copy-file (make-path *STATIC-DIR* s)
						   (make-path static-output-dir s))
				   (cons :location s)))
		     (mapcar 
		      (lambda (p) (file-namestring p))
		      (directory (make-pathname :defaults *STATIC-DIR*
					       :name :wild
					       :type :wild))))))
    (push (cons :static static-list) *GLOBAL-CONTEXT*)))
Cherie Yang's avatar
Cherie Yang committed
33 34 35 36

;; process-pages : Copies/renders pages - called last
(defun render-page (page template-path)
  (let* 
37 38
    ((page-path (make-path *PAGES-DIR* page t))
     (output-path (make-path *OUTPUT-DIR* page t))
Cherie Yang's avatar
Cherie Yang committed
39 40 41 42 43 44
     (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) 
45 46
        (mustache:render template-path (append page-context *GLOBAL-CONTEXT*) 
			 output-stream))))
Cherie Yang's avatar
Cherie Yang committed
47 48 49 50 51 52 53

(defun process-pages () 
  (let 
      ((template-path (pathname (merge-pathnames *LAYOUT-DIR* *DEFAULT-PAGE-TEMPLATE*))))
    (progn (ensure-directories-exist *OUTPUT-DIR*)
    (loop for page in *PAGES*
       do (render-page page template-path)))))