Flexible Lisp Blogware. Fork for personal use. Mirrored from https://github.com/kingcons/coleslaw originally.

incremental.lisp 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. (eval-when (:compile-toplevel :load-toplevel)
  2. (ql:quickload 'cl-store))
  3. (defpackage :coleslaw-incremental
  4. (:use :cl)
  5. (:import-from :coleslaw #:get-updated-files
  6. #:find-content-by-path
  7. #:write-document)
  8. (:export #:enable))
  9. (in-package :coleslaw-incremental)
  10. ;; FIXME: We currently never update the site for config changes.
  11. ;; Examples to consider include changing the theme or domain of the site.
  12. ;; NOTE: We're gonna be a bit dirty here and monkey patch. The compilation model
  13. ;; still isn't an "exposed" part of Coleslaw. After some experimentation maybe
  14. ;; we'll settle on an interface.
  15. (defvar *changed-content* nil
  16. "A list of changed content instances to iterate over and write out to disk.")
  17. (defun coleslaw::load-content ()
  18. ;; TODO: What if the file doesn't exist?
  19. (let ((db-file (rel-path (user-homedir-pathname) ".coleslaw.db")))
  20. (setf coleslaw::*site* (cl-store:restore db-file))
  21. (loop for (status path) in (get-updated-files)
  22. do (update-content status path))
  23. (cl-store:store coleslaw::*site* db-file)))
  24. (defun update-content (status path)
  25. (cond ((string= "D" status) (process-change :deleted path))
  26. ((string= "M" status) (process-change :modified path))
  27. ((string= "A" status) (process-change :added path))))
  28. (defgeneric process-change (status path)
  29. (:documentation "Updates the database as needed for the STATUS change to PATH."))
  30. (defun coleslaw::compile-blog (staging)
  31. "lulz. Do it live. DO IT ALL LIVE."
  32. ;; FIXME: This doesn't cover prev/next links for posts, theme-fn for feeds.
  33. (mapcar #'write-document *changed-content*))
  34. ;; No-op. We'll be updating in place instead.
  35. (defmethod coleslaw:deploy (staging))
  36. (defun enable ())