diff --git a/guile-docs.scm b/guile-docs.scm index b0fe7d5..a578b84 100644 --- a/guile-docs.scm +++ b/guile-docs.scm @@ -2,7 +2,8 @@ ;; https://spritely.institute/files/docs/guile-hoot/0.2.0/Tutorial.html (use-modules (ice-9 binary-ports) (ice-9 format) (ice-9 match) - (web server) (web request) (web response) (web uri)) + (web server) (web request) (web response) (web uri) + (haunt html)) (define (extension file) (match (string-split file #\.) @@ -12,13 +13,21 @@ (define (mime-type file-name) (or (assoc-ref '(("js" . application/javascript) ("html" . text/html) + ("scm" . text/stml) ("wasm" . application/wasm)) (extension file-name)) 'text/plain)) +(define (render-stml file-name) + (values '((content-type . (text/html))) + (sxml->html-string (load file-name)))) + (define (render-file file-name) - (values `((content-type . (,(mime-type file-name)))) - (call-with-input-file file-name get-bytevector-all))) + (let ((type (mime-type file-name))) + (if (eq? type 'text/stml) + (render-stml file-name) + (values `((content-type . (,type))) + (call-with-input-file file-name get-bytevector-all))))) (define (not-found path) (values (build-response #:code 404) (string-append "Not found: " path))) @@ -34,7 +43,7 @@ (cond ((and (file-exists? f) (not (directory? f))) (render-file f)) ((equal? "/" path) - (render-file (prepend-prefix "index.html"))) + (render-file (prepend-prefix "index.scm"))) (else not-found path)))) (define (handle-request request body) diff --git a/public/index.html b/public/index.html deleted file mode 100644 index d8d2a27..0000000 --- a/public/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - -
-This is Guile Docs.
- - diff --git a/public/index.scm b/public/index.scm new file mode 100644 index 0000000..6895178 --- /dev/null +++ b/public/index.scm @@ -0,0 +1,6 @@ +'(html + (head + (title "Welcome to Guile Docs")) + (body + (h1 "Welcome to Guile Docs") + (p "This is Guile Docs.")))