Only generate book list if database or template has changed since last run
[clinton/website/site-support.git] / books.lisp
index fae9a1d..383baea 100644 (file)
 (defun book-database-vars (book-database)
   `(:authors ,(mapcar #'author-vars book-database)))
 
-(defun dump-muse-books-file (&optional (muse-path *muse-pathname*)
-                                      (book-path *book-pathname*)
-                                      (template-path *template-pathname*))
-  (with-open-file (muse-stream muse-path
-                              :direction :output
-                              :element-type 'extended-char
-                              :if-exists :overwrite
-                              :if-does-not-exist :create)
-    (html-template:fill-and-print-template
-     template-path
-     (book-database-vars
-      (with-open-file (book-stream book-path :element-type 'extended-char)
-       (read book-stream)))
-     :stream muse-stream)))
+(defun dump-muse-books-file (&key (muse-path *muse-pathname*)
+                                 (book-path *book-pathname*)
+                                 (template-path *template-pathname*)
+                                 (force nil))
+  (when (or force
+           (> (file-write-date book-path) (file-write-date muse-path))
+           (> (file-write-date template-path) (file-write-date muse-path)))
+    (with-open-file (muse-stream muse-path
+                                :direction :output
+                                :element-type 'extended-char
+                                :if-exists :supersede
+                                :if-does-not-exist :create)
+      (html-template:fill-and-print-template
+       template-path
+       (book-database-vars
+       (with-open-file (book-stream book-path :element-type 'extended-char)
+         (read book-stream)))
+       :stream muse-stream))))