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

coleslaw.lisp 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. (in-package :coleslaw)
  2. (defun render-page (path html &optional raw)
  3. "Populate the base template with the provided HTML and write it out to PATH.
  4. If RAW is non-nil, write the content without wrapping it in the base template."
  5. (let ((filepath (merge-pathnames path (staging *config*))))
  6. (ensure-directories-exist filepath)
  7. (with-open-file (out filepath
  8. :direction :output
  9. :if-does-not-exist :create)
  10. (let ((content (funcall (theme-fn "BASE")
  11. (list :title (title *config*)
  12. :siteroot (domain *config*)
  13. :navigation (sitenav *config*)
  14. :content html
  15. :head-inject (apply #'concatenate 'string
  16. (gethash :head *injections*))
  17. :body-inject (apply #'concatenate 'string
  18. (gethash :body *injections*))
  19. :license (license *config*)
  20. :credits (author *config*)))))
  21. (write-line (if raw html content) out)))))
  22. (defun compile-blog (staging)
  23. "Compile the blog to a STAGING directory as specified in .coleslawrc."
  24. ; TODO: More incremental compilation? Don't regen whole blog unnecessarily.
  25. (when (probe-file staging)
  26. (cl-fad:delete-directory-and-files staging))
  27. (ensure-directories-exist staging)
  28. (with-current-directory staging
  29. (let ((css-dir (app-path "themes/~a/css" (theme *config*)))
  30. (static-dir (merge-pathnames "static" (repo *config*))))
  31. (dolist (dir (list css-dir static-dir))
  32. (when (probe-file dir)
  33. (shell-command (format nil "cp -R ~a ." dir)))))
  34. (render-posts)
  35. (render-indices)
  36. (render-feed)))
  37. (defun update-symlink (path target)
  38. "Update the symlink at PATH to point to TARGET."
  39. (shell-command (format nil "ln -sfn ~a ~a" target path)))
  40. (defgeneric deploy (staging)
  41. (:documentation "Deploy the STAGING dir, updating the .prev and .curr symlinks.")
  42. (:method (staging)
  43. (flet ((deploy-path (path &rest args)
  44. (merge-pathnames (apply 'format nil path args) (deploy *config*))))
  45. (let ((new-build (deploy-path "generated/~a" (get-universal-time)))
  46. (prev (deploy-path ".prev"))
  47. (curr (deploy-path ".curr")))
  48. (ensure-directories-exist new-build)
  49. (with-current-directory coleslaw-conf:*basedir*
  50. (shell-command (format nil "mv ~a ~a" staging new-build))
  51. (if (and (probe-file prev) (equal prev (truename prev)))
  52. (delete-file prev)
  53. (cl-fad:delete-directory-and-files (truename prev)))
  54. (when (probe-file curr)
  55. (update-symlink prev (truename curr)))
  56. (update-symlink curr new-build))))))
  57. (defun main ()
  58. "Load the user's config, then compile and deploy the blog."
  59. (load-config)
  60. (compile-theme (app-path "themes/~a/" (theme *config*)))
  61. (compile-blog (staging *config*))
  62. (deploy (staging *config*)))