commit 6ae237e3046bf27a5234081fc1d7de1393453390
parent 41a95bc2dab2367e546283a5a5fa777f514f0d40
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 9 Sep 2026 23:50:13 +0100
look in CRIPSLOCK_DIR for static files not found in site
this is so we can put boxy.{js,css} under version control
Diffstat:
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/main.fnl b/main.fnl
@@ -3,6 +3,7 @@
(local lcmark (require :lcmark))
(local cqueues (require :cqueues))
(local url (require :net.url))
+(local unistd (require :posix.unistd))
(local server (require :server))
(local textile (require :textile))
@@ -13,9 +14,11 @@
(local { : string-stream : prepend : %% : trace : clone } (require :lib))
(local { : Path } (require :path))
-
(local { : view } (require :fennel))
+(local cripslock-dir (case (os.getenv "CRIPSLOCK_DIR") p (Path p)))
+
+
(fn route-request [method path matchers]
(accumulate [matched nil
_ pred (ipairs matchers)
@@ -32,7 +35,7 @@
[ :month { :year (tonumber year) :month (tonumber month) } ]
foo (print :fo foo)
)
- #(case (string.match $2 "^(/static/%g+)")
+ #(case (string.match $2 "^/(static/%g+)")
path
[ :static { : path } ])
@@ -339,6 +342,9 @@ href=\"https://axillae.telent.net/\">@dan@axillae.telent.net</a>
{ :content-type "application/rss+xml; charset=utf-8" })
(rss.feed stream "https://ww.telent.net" collection posts)))
+(fn existing-file [name]
+ (let [n (tostring name)]
+ (and (unistd.access n) n)))
(fn dispatch [route stream collection]
(print (view route))
@@ -356,7 +362,10 @@ href=\"https://axillae.telent.net/\">@dan@axillae.telent.net</a>
[:month { : month : year }]
(send-month-page stream collection year month)
[:static { : path }]
- (let [realpath (collection:static-file path)]
+ (let [realpath
+ (or (existing-file (collection:static-file path))
+ (existing-file (/ cripslock-dir path)))]
+
(with-open [f (io.open realpath :r)]
(server.headers stream
{ :content-type (content-type-for-path realpath) })