diff --git a/resource/coerse-content-bytes.rkt b/resource/coerse-content-bytes.rkt new file mode 100644 index 0000000..f878dd7 --- /dev/null +++ b/resource/coerse-content-bytes.rkt @@ -0,0 +1,19 @@ +#lang racket/base + +(provide coerse-content-bytes) +(require (planet neil/html-parsing) + (planet neil/html-writing)) + +;; coerse-content-bytes: path bytes -> bytes +;; Given some bytes, we may need to do some data validation or cleanup. +;; In particular, when the file's HTML, we need to make sure we're +;; storing syntactically valid HTML. +(define (coerse-content-bytes a-path bytes) + (cond + [(regexp-match #rx"\\.html$" + (path->string a-path)) + (define op (open-output-bytes)) + (write-html (html->xexp (open-input-bytes bytes)) op) + (get-output-bytes op)] + [else + bytes])) \ No newline at end of file diff --git a/resource/compile-time.rkt b/resource/compile-time.rkt index a9d40b3..759e83b 100644 --- a/resource/compile-time.rkt +++ b/resource/compile-time.rkt @@ -4,6 +4,7 @@ racket/path racket/port syntax/parse + "coerse-content-bytes.rkt" "munge-path.rkt" "record.rkt")) @@ -27,7 +28,8 @@ (current-directory)) (syntax-e #'path)))] [munged-path (munge-path normal-path)] - [content (call-with-input-file normal-path port->bytes)]) + [content (coerse-content-bytes normal-path + (call-with-input-file normal-path port->bytes))]) (with-syntax ([normal-path normal-path] [munged-path munged-path] [content content])