summaryrefslogtreecommitdiff
path: root/tempest.lisp
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-08-26 21:14:55 +0800
committereltrac <hi@eltr.ac>2026-08-26 21:14:55 +0800
commitbdeb8e4b397dcf3ba61ac1d38e046236f8d44a5d (patch)
tree50afc74efe4c09eb9a6e4f78b12a3da419c4a7ad /tempest.lisp
parent17b4dd905c7d02cdeb841da8ce97416c173fe8df (diff)
main: read/eval lisp and compile to html file
Diffstat (limited to 'tempest.lisp')
-rw-r--r--tempest.lisp34
1 files changed, 30 insertions, 4 deletions
diff --git a/tempest.lisp b/tempest.lisp
index 34b8c01..e08b4d0 100644
--- a/tempest.lisp
+++ b/tempest.lisp
@@ -2,11 +2,37 @@
(defparameter path-to-watch "./")
-(defun main ()
+(defun read-tempest-string (filename)
+ "Read file content as string. If it's not a .lisp file and does not have tempest comment at top, return NIL."
+ (let ((content (uiop:read-file-string filename)))
+ (if (and (str:ends-with-p ".lisp" filename :ignore-case T)
+ (str:starts-with-p ";;;; TEMPEST" content))
+ content NIL)))
+
+(defun compile-to-html (tempest-string)
+ "Compile tempest file content to HTML string using spinneret."
+ (let ((*read-eval* nil))
+ (-> (concatenate 'string "(spinneret:with-html " tempest-string ")")
+ read-from-string
+ eval)))
+
+(defun build-template (filename)
+ (let ((raw (read-tempest-string filename)))
+ (if raw
+ (let ((target-file (str:replace-all ".lisp" ".html" filename)))
+ (with-open-file (*standard-output* target-file
+ :direction :output
+ :if-exists :supersede
+ :if-does-not-exist :create)
+ (compile-to-html raw)
+ target-file))
+ NIL)))
+
+(defun watch ()
(file-notify:watch path-to-watch)
(file-notify:with-events (file change :timeout T)
(when (str:ends-with-p ".lisp" file :ignore-case T)
- (print (list file change))))
- (format t "Tempest is starting."))
+ (print (list file change)))))
-(main)
+(defun main ()
+ )