Commit 6058f17a3bec1961a65f81539120afe450b60ef0

Thomas de Grivel 2020-04-18T14:55:51

static-file static-directory

diff --git a/core/helpers.lisp b/core/helpers.lisp
index f72ac9b..4847c7b 100644
--- a/core/helpers.lisp
+++ b/core/helpers.lisp
@@ -28,3 +28,20 @@
                (when (zerop size)
                  (return))
                (write-sequence buf out :end size))))))))
+
+(defun static-file (path &rest plist)
+  (resource 'file path
+            :content (read-file (hostname *host*) path)
+            plist))
+
+(defun static-directory (directory &rest plist)
+  (let* ((host-dir (truename (pathname (the string
+                                            (str (hostname) #\/)))))
+         (dir-path (str host-dir directory)))
+    (print dir-path)
+    (mapcar (lambda (path)
+              (let ((name (enough-namestring path host-dir)))
+              (resource 'file (str "/" name)
+                        :content (read-file path)
+                        plist)))
+                  (directory dir-path))))
diff --git a/package.lisp b/package.lisp
index b195fca..fecb545 100644
--- a/package.lisp
+++ b/package.lisp
@@ -153,6 +153,8 @@
    ;; helpers
    #:include
    #:read-file
+   #:static-file
+   #:static-directory
    #:str
    ))