aboutsummaryrefslogtreecommitdiffstats
path: root/app.scm
diff options
context:
space:
mode:
Diffstat (limited to 'app.scm')
-rw-r--r--app.scm50
1 files changed, 46 insertions, 4 deletions
diff --git a/app.scm b/app.scm
index 7b22dbf..683dc5f 100644
--- a/app.scm
+++ b/app.scm
@@ -15,7 +15,8 @@
shell
srfi-13
intarweb
- html-parser)
+ html-parser
+ (chicken process))
(define (pipe x . fns)
(match fns
@@ -25,8 +26,13 @@
;; Convenience macro (@ expr ...) that expands to (lambda (x) (expr ... x))
(define-syntax @
(syntax-rules ()
- ((_ fn-body expr ...)
- (lambda (x) (fn-body expr ... x)))))
+ ((_ expr ...)
+ (lambda (x) (expr ... x)))))
+
+(define-syntax thunk
+ (syntax-rules ()
+ ((_ expr ...)
+ (lambda () (expr ...)))))
(define (replace from to str)
(irregex-replace/all from str to))
@@ -89,12 +95,48 @@
(send-response body: html-text
headers: '((content-type #(text/html ((charset . utf-8)))))))
+(define (compile-file filepath return)
+ (if (not (irregex-search "\\.md$" filepath))
+ (begin
+ (print (format "Copying non-md file: ~A" filepath))
+ (copy-file filepath
+ (replace "pages\\/" "dist/" filepath))
+ (return (void))))
+
+ (print (format "Compiling: ~A" filepath))
+ (define out-path (pipe filepath
+ (@ replace "\\.md" ".html")
+ (@ replace "pages\\/" "dist/")))
+
+ (define out-content (pipe filepath
+ (@ convert-md-to-html)
+ (@ highlight-code-blocks)
+ (@ insert-to-page-tmpl "index.html")))
+
+ (with-output-to-file out-path
+ (thunk display out-content)))
+
+(define (recompile)
+ (create-directory "dist" #t)
+ (for-each (@ delete-file) (glob "dist/*"))
+ (find-files "pages"
+ action: (lambda (filepath prev-result) (call/cc (lambda (k) (compile-file filepath k))))))
+
+(thread-start!
+ (lambda ()
+ (receive (input _ _) (process "fswatch -o pages")
+ (let loop ()
+ (print (format "Monitored directory has changed (# of changes: ~A)" (read-line input)))
+ (recompile)
+ (loop)))))
+
(thread-start!
(lambda ()
(print "starting nrepl on port 1234")
(nrepl-prompt (lambda () (display "#;0> ")))
(nrepl 1234)))
-(vhost-map `((".*" . ,(lambda (c) (app c)))))
+(recompile)
+(vhost-map `((".*" . ,(lambda (c) (app c)))))
(start-server)