From f03dcea8d512b661f7f4156367e0ce09ea20f2b0 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 25 Mar 2024 22:48:16 +0200 Subject: Initial commit --- .gitignore | 3 ++ main.scm | 87 +++++++++++++++++++++++++++++++++++++++++++++ template.html | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 .gitignore create mode 100644 main.scm create mode 100644 template.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f494f20 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +pages +out + diff --git a/main.scm b/main.scm new file mode 100644 index 0000000..eb46fad --- /dev/null +++ b/main.scm @@ -0,0 +1,87 @@ +(import (chicken base) + (chicken io) + (chicken file posix) + (chicken file) + (chicken string) + (chicken pathname) + (chicken format) + (chicken process-context) + (chicken irregex) + (chicken process) + (matchable)) + +; utils + +(define-syntax @ + (syntax-rules () + ((_ fn-body expr ...) + (lambda (x) (fn-body expr ... x))))) + +(define (last lst) + (if (null? (cdr lst)) + (car lst) + (last (cdr lst)))) + +(define (pipe x . fns) + (match fns + [() x] + [(fn . rest) (apply pipe (fn x) rest)])) + +(define (flow . fns) + (lambda (x) (apply pipe x fns))) + +; application + +(define src-dir (or (get-environment-variable "SRC_DIR") + "pages")) +(define out-dir (or (get-environment-variable "OUT_DIR") + "out")) +(define template-path (or (get-environment-variable "PANDOC_TEMPLATE") + "template.html")) + +(define (process-path path) + (match path + [(? is-md?) (process-md path)] + [(? directory?) (process-dir (format "~A" path))] + [other (printf "TODO other file ~A~%" path)])) + +(define (is-md? path) + (define parts (string-split path ".")) + (string=? "md" (last parts))) + +(define (process-md md-path) + (define out-html-file (pipe md-path + (lambda (p) (irregex-replace (format "^~A" src-dir) p out-dir)) + (lambda (p) (irregex-replace "\.md$" p ".html")))) + + (define-values (html-dir html-filename html-ext) (decompose-pathname out-html-file)) + (create-directory html-dir #t) + (pandoc-md-to-html md-path out-html-file)) + +(define (pandoc-md-to-html md-path html-path) + (define args (list md-path + "-o" html-path + "--standalone" + "--template" template-path + "--highlight-style" "pygments")) + (printf "pandoc ~A" args) + (process "pandoc" args)) + +(define (process-dir dir-path) + (define out-dir-path (irregex-replace (format "^~A" src-dir) out-dir)) + (create-directory out-dir-path #t) + (define paths (glob (format "~A/*" dir-path))) + (define paths (map (lambda (p) (irregex-replace "^\./" p "")) paths)) + (for-each process-path paths)) + +(define (clean-dir dir) + (define (delete path) + (if (directory? path) + (delete-directory path #t) + (delete-file path))) + (for-each (@ delete) (glob (format "~A/*" dir)))) + +; run + +(clean-dir out-dir) +(process-dir src-dir) diff --git a/template.html b/template.html new file mode 100644 index 0000000..d0160cd --- /dev/null +++ b/template.html @@ -0,0 +1,111 @@ + + + + + + +$for(author-meta)$ + +$endfor$ +$if(date-meta)$ + +$endif$ +$if(keywords)$ + +$endif$ +$if(description-meta)$ + +$endif$ + $if(title-prefix)$$title-prefix$ – $endif$$pagetitle$ + + + + + + + + +$for(header-includes)$ + $header-includes$ +$endfor$ +$if(math)$ +$if(mathjax)$ + +$endif$ + $math$ +$endif$ + + +
+

jan's garden

+
+
+ + +$body$ + + + + + -- cgit v1.3