From 443582b2667e86ecac47de7bb77cbcc5bb354256 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Wed, 4 Oct 2023 16:45:01 +0200 Subject: html: js and css work as media and as raw strings --- src/html.scm | 16 ++++++++-------- tests/html.scm | 11 ++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/html.scm b/src/html.scm index 107b78c..7c0485f 100644 --- a/src/html.scm +++ b/src/html.scm @@ -109,9 +109,6 @@ uri path)) -(define css media) -(define js media) - (define* (person name #:key (email "") (uri "") #:allow-other-keys) @@ -136,12 +133,15 @@ ,(post-content-html post)))) (define (render-style style) - ;; TODO it escapes the contents!! if added inline :( - `(link (@(rel stylesheet) - (href ,(media-uri style))))) + (if (media? style) + `(link (@(rel stylesheet) + (href ,(media-uri style)))) + `(style ,(lambda () (display style))))) + (define (render-script script) - ;; TODO it escapes the contents!! if added inline :( - `(script (@(src ,(media-uri script))))) + (if (media? script) + `(script (@(src ,(media-uri script)))) + `(script ,(lambda () (display script))))) (define (render-index index) `(html diff --git a/tests/html.scm b/tests/html.scm index c5a5967..ca041f4 100644 --- a/tests/html.scm +++ b/tests/html.scm @@ -13,9 +13,11 @@ #:description "Este es mi feed" #:uri "https://feed.elenq.tech/index.html" #:styles (list - (html:css "this.css" #:uri "/this.css") - (html:css "that.css" #:uri "/that.css")) - #:scripts (list (html:js "script.js" #:uri "/script.js")) + "body {color: grey}" + (html:media "that.css" #:uri "/that.css")) + #:scripts (list + "console.log(\"HOLA\")" + (html:media "script.js" #:uri "/script.js")) #:author me #:posts (list (html:post #:title "first entry" @@ -29,7 +31,6 @@ (let ((html-index (with-output-to-string (lambda () (html:render index))))) (test-assert (string=? html-index - "

first entry

Ekaitz

Este es el resumen

Este es el contenido