diff options
| -rw-r--r-- | app.scm | 39 | ||||
| -rw-r--r-- | requirements.list | 2 |
2 files changed, 35 insertions, 6 deletions
@@ -18,7 +18,8 @@ uri-common (chicken process) (chicken process-context) - (chicken condition)) + (chicken condition) + trace) (define *PORT* (get-environment-variable "PORT")) (define *WEBROOT* (or (get-environment-variable "WEBROOT") @@ -84,9 +85,36 @@ (@ highlight lang) (@ string-trim-both))) +(define (try-with-backoff thunk + #!optional (backoffs (list 10 50 150 500))) + (define (inner boffs return) + (call/cc + (lambda (k) + (with-exception-handler (lambda (exn) (k exn)) + (lambda () (return (thunk)))))) + + (if (null? boffs) (return #f)) + (thread-sleep! (/ (car boffs) 1000.0)) + (inner (cdr boffs) return)) + + (call/cc (lambda (k) (inner backoffs k)))) + (define (convert-md-to-html filepath) - (with-output-to-string - (lambda () (markdown->html (open-input-file filepath))))) + (define (read-md) + (define result (read-string #f (open-input-file filepath))) + (if (eq? #!eof result) + (error 'eof "md file is empty")) + result) + + (define md (try-with-backoff read-md)) + + (if (string? md) + (with-output-to-string + (lambda () (markdown->html (open-input-string md)))) + + ;; else + (begin (print "warning: md file " filepath " seems to be empty!") + ""))) (define (highlight-code-blocks html) (define (highlight-match m) @@ -97,8 +125,9 @@ highlight-match)) (define (insert-to-page-tmpl tmpl-path html) - (format (read-string #f (open-input-file tmpl-path)) - html)) + (define tmpl-port (open-input-file tmpl-path)) + (define tmpl-string (read-string #f tmpl-port)) + (format tmpl-string html)) (define (system-has-fswatch?) (call/cc (lambda (k) diff --git a/requirements.list b/requirements.list index 2bece13..d5ae3a6 100644 --- a/requirements.list +++ b/requirements.list @@ -9,4 +9,4 @@ (utf8 "3.6.3") (nrepl "5.0.8") (matchable "1.1") - +(trace "2.0") |
