My personal website, goal is to have a blog and a "resume".

functions.lisp 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. (ql:quickload :coleslaw)
  2. (ql:quickload :hunchentoot)
  3. (ql:quickload :cl-inotify) ; Had to apt-get install libfixposix-dev
  4. (ql:quickload :iterate)
  5. (ql:quickload :bordeaux-threads)
  6. (defpackage :azrazalea-net
  7. (:use cl iterate cl-inotify bordeaux-threads)
  8. (:export build-coleslaw start-server stop-server deploy))
  9. (in-package :azrazalea-net)
  10. (defun build-coleslaw ()
  11. "Builds site with coleslaw. Makes the assumption that the directory the lisp image
  12. was started in is the site directory."
  13. (coleslaw:main *default-pathname-defaults*))
  14. (defun watch-recursive (things)
  15. (iter
  16. (with inotify = (make-inotify))
  17. (with flags = '(:create :modify :delete))
  18. (for dir in things)
  19. (watch inotify dir flags)
  20. (iter (for subdir in (uiop:subdirectories dir))
  21. (watch inotify subdir flags))
  22. (finally (do-events (event inotify :blocking-p t)
  23. (build-coleslaw)))))
  24. (let ((acceptor (make-instance 'hunchentoot:easy-acceptor :document-root (merge-pathnames "dist/") :port 4242))
  25. (file-things (mapc
  26. (lambda (name) (merge-pathnames name))
  27. '("pages/"
  28. "static/"
  29. "posts/"
  30. "themes/"
  31. ".coleslawrc")))
  32. (inotify-thread nil))
  33. (defun start-server ()
  34. "Starts a hunchentoot server that serves the site on port 4242"
  35. (when inotify-thread (destroy-thread inotify-thread))
  36. (setf inotify-thread (make-thread (lambda ()
  37. (watch-recursive file-things)) :name "inotify"))
  38. (hunchentoot:start acceptor))
  39. (defun stop-server ()
  40. "Stops a hunchentoot server that serves the site on port 4242"
  41. (when inotify-thread (destroy-thread inotify-thread))
  42. (setf inotify-thread nil)
  43. (hunchentoot:stop acceptor)))
  44. (defun deploy ()
  45. (uiop:run-program "rsync -az --delete dist/ --exclude .well-known/ web-admin@azrazalea.net:www/"))