From bdeb8e4b397dcf3ba61ac1d38e046236f8d44a5d Mon Sep 17 00:00:00 2001 From: eltrac Date: Wed, 26 Aug 2026 21:14:55 +0800 Subject: main: read/eval lisp and compile to html file --- tempest.lisp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'tempest.lisp') 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 () + ) -- cgit v1.2.3