summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2024-06-26 19:30:12 +0300
committerJan Tuomi <jan@jantuomi.fi>2024-06-26 19:30:12 +0300
commit0a2c7230225e80942380d4f2f90e47c5cb7a197b (patch)
tree1475d0e534ed15a8af566711a4374055c58e064d
parent47da2ad3925a122d8e97ebe66434ea06195b9eff (diff)
Add eof and empty result handling
-rw-r--r--main.scm11
-rw-r--r--md-parser.scm3
2 files changed, 10 insertions, 4 deletions
diff --git a/main.scm b/main.scm
index 9e6b9ad..672777c 100644
--- a/main.scm
+++ b/main.scm
@@ -41,10 +41,15 @@
(assert (> (string-length out-dir) 0))
(assert (> (string-length template-path) 0))
-
(define (preprocess-md md-path out-path)
- (define md (with-input-from-file md-path
- (λ () (read-string #f))))
+ (define md-or-eof (with-input-from-file md-path
+ (λ () (read-string #f))))
+
+ (define md (if (eof-object? md-or-eof)
+ (begin (printf "[warn] \"~A\" is empty, using an empty md file...~%" md-path)
+ "")
+ ;; else
+ md-or-eof))
(define cwd (decompose-pathname md-path))
(define out-path-dir (decompose-pathname out-path))
diff --git a/md-parser.scm b/md-parser.scm
index accc927..7cf3d45 100644
--- a/md-parser.scm
+++ b/md-parser.scm
@@ -40,7 +40,8 @@
(λ () (read-lines))))
(define (inner return)
- (if (not (string=? "---" (car lines)))
+ (if (or (null? lines)
+ (not (string=? "---" (car lines))))
(return #f))
(define fm (collect-fm-lines (cdr lines)))