commit 8da3e78b62c26cc5f053007ae82d8cae656cce3a parent a139f8e797859f017146af8256dbad6cf8862f26 Author: Daniel Barlow <dan@telent.net> Date: Tue, 5 Aug 2025 23:23:42 +0100 hook up inotify so we can reload when files change this is not the final form! - it needs to know the pathname of each post, so it should be moved to the site module - the notifier needs to be refreshed whenever the site is refreshed otherwise it won't notice new files after their first write Diffstat:
| M | main.fnl | | | 28 | ++++++++++++++++++++++------ |
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/main.fnl b/main.fnl @@ -2,6 +2,9 @@ (local lfs (require :lfs)) (local lcmark (require :lcmark)) +(local cqueues (require :cqueues)) +(local notify (require :cqueues.notify)) + (local server (require :server)) (local textile (require :textile)) (local site (require :site)) @@ -294,13 +297,26 @@ href=\"https://axillae.telent.net/\">@dan@axillae.telent.net</a> (dispatch route stream) (server.headers stream { ":status" :404 } true)))) -(fn run [] - (let [myserver (server.new { :onstream http-handler } )] - (myserver:loop))) +(fn watch-files [site] + (let [n (notify.opendir site.path notify.ALL)] + (each [_ p (ipairs (site:search {}))] + (n:add p.path)) + n)) -;; (with-open [f (io.open "data/blogs/telent.blog/posts//20201203_Internet_of_Bling.textile")] -;; (each [_ el (ipairs (textile.parse f))] -;; (textile.to-html io.stdout el))) +(fn run [] + (let [event-loop (cqueues.new) + myserver (server.new { :onstream http-handler } ) + watcher (watch-files post-index) + ] + (event-loop:wrap #(myserver:loop)) + (event-loop:wrap + (fn [] + (while true + (case (watcher:get) + (flags name) + (do (print "notified " flags "on" name) + (post-index:refresh)))))) + (event-loop:loop))) {: run }