blog: Try to skip unmodified posts
authorLucian Mogosanu <lucian.mogosanu@gmail.com>
Sun, 19 Mar 2017 10:47:03 +0000 (12:47 +0200)
committerLucian Mogosanu <lucian.mogosanu@gmail.com>
Sun, 19 Mar 2017 10:47:03 +0000 (12:47 +0200)
Disclaimer: verify this with much caution.

blog.lisp
lbs-utils/utils.lisp

index 5841d15..9471fc8 100644 (file)
--- a/blog.lisp
+++ b/blog.lisp
                    (concatenate 'string *lbs-base* relative-wildcard))))
     (assert (not (null postlist)))
     (dolist (x postlist)
-      (format t "[proc] ~s~%" x)
       (let* ((relative-pathname (post-relative-pathname x))
-             (blist (tlbs-make-blist relative-pathname)))
-        ; markdown -> html
-        (pipe-through-pandoc blist)
-        ; process tags
+             (blist (tlbs-make-blist relative-pathname))
+             (in-path (gethash "in-path" blist))
+             (out-path (gethash "out-path" blist)))
+        ;; process tags
         (tlbs-make-tagids blist)
-        ; post template
-        (tlbs-make-post blist)
-        ; default page template
-        (tlbs-make-default blist)
-        ; write to file
-        (tlbs-write-blist blist)
-        ; make sure body is erased when done writing
-        ; XXX: the body might still be needed when generating RSS
-        (setf (gethash "body" blist) nil)
-        ; add to post list
+        (when (file-modified in-path out-path)
+            (format t "[proc] ~s~%" x)
+            ;; markdown -> html
+            (pipe-through-pandoc blist)
+            ;; post template
+            (tlbs-make-post blist)
+            ;; default page template
+            (tlbs-make-default blist)
+            ;; write to file
+            (tlbs-write-blist blist)
+            ;; make sure body is erased when done writing
+            ;; XXX: the body might still be needed when generating RSS
+            (setf (gethash "body" blist) nil))
+        ;; add to post list
         (push blist *posts*))))
   nil)
 
       (let* ((relative-pathname (post-relative-pathname in-path))
              (out-path (concat-pathnames out-base-dir
                                          relative-pathname)))
-        (format t "[copy] ~s~%" in-path)
-        (tlbs-copy-file in-path out-path))
+        ;; XXX This probably not too reliable, would need to keep some
+        ;; hashes...
+        (when (file-modified in-path out-path)
+            (format t "[copy] ~s~%" in-path)
+            (tlbs-copy-file in-path out-path)))
       (dolist (new-in-path (directory (concat-pathnames in-path #p"*.*")))
         (tlbs-copy-recursively new-in-path out-base-dir))))
 
index 620a869..5e59673 100644 (file)
@@ -1,6 +1,6 @@
-;; Tarpit LBS utility library
+;;; Tarpit LBS utility library
 
-; This assumes pathnames are absolute to *lbs-base*
+;; This assumes pathnames are absolute to *lbs-base*
 (defun post-relative-pathname (pathname)
   (enough-namestring pathname (pathname *lbs-base*)))
 
    :name (pathname-name path2)
    :type (pathname-type path2)))
 
+;; XXX Not sure this should look this way. Probably comparing in-path to
+;; a reference hash of out-path might be better.
+(defun file-modified (in-path out-path)
+  (or (not (probe-file out-path))
+                (> (sb-posix:stat-mtime (sb-posix:stat in-path))
+                   (sb-posix:stat-mtime (sb-posix:stat out-path)))))
+
 ;; General utility functions
 (defun but-last (L)
   (let ((ret nil))