content bytes for resources now go through a coersion/cleanup stage. Currently we're only doing HTML, since web-world requires well-formed HTML.
This commit is contained in:
parent
5de0164064
commit
4bc4f0c15c
19
resource/coerse-content-bytes.rkt
Normal file
19
resource/coerse-content-bytes.rkt
Normal file
|
@ -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]))
|
|
@ -4,6 +4,7 @@
|
||||||
racket/path
|
racket/path
|
||||||
racket/port
|
racket/port
|
||||||
syntax/parse
|
syntax/parse
|
||||||
|
"coerse-content-bytes.rkt"
|
||||||
"munge-path.rkt"
|
"munge-path.rkt"
|
||||||
"record.rkt"))
|
"record.rkt"))
|
||||||
|
|
||||||
|
@ -27,7 +28,8 @@
|
||||||
(current-directory))
|
(current-directory))
|
||||||
(syntax-e #'path)))]
|
(syntax-e #'path)))]
|
||||||
[munged-path (munge-path normal-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]
|
(with-syntax ([normal-path normal-path]
|
||||||
[munged-path munged-path]
|
[munged-path munged-path]
|
||||||
[content content])
|
[content content])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user