From 743c86f7db8ad8bd7f64a38a675f405296165101 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 7 Feb 2024 13:34:16 +0200 Subject: Support subdirectories --- app.scm | 58 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/app.scm b/app.scm index 683dc5f..a98d21a 100644 --- a/app.scm +++ b/app.scm @@ -95,32 +95,46 @@ (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 (compile-file filepath prev-result) + (define (inner return) + (if (directory-exists? filepath) + (begin + (print (format "Creating corresponding directory: ~A" filepath)) + (create-directory (replace "^pages\\/" "dist/" filepath) #t) + (return (void)))) + + (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 markdown: ~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))) + + (call/cc inner)) (define (recompile) (create-directory "dist" #t) - (for-each (@ delete-file) (glob "dist/*")) + + (define (delete-path path) + (if (directory-exists? path) + (delete-directory path #t) + (delete-file path))) + (for-each delete-path (glob "dist/*")) (find-files "pages" - action: (lambda (filepath prev-result) (call/cc (lambda (k) (compile-file filepath k)))))) + action: compile-file)) (thread-start! (lambda () -- cgit v1.3