From 30029b00d11aef1fd7ec953bfb372248ba8d5847 Mon Sep 17 00:00:00 2001 From: Tony Day Date: Fri, 29 Dec 2023 20:17:04 +1000 Subject: [PATCH] Bug fix --- ChangeLog.md | 6 +++++- src/Web/Rep.hs | 1 + src/Web/Rep/Page.hs | 22 ++++++++++++++++++++++ src/Web/Rep/Render.hs | 6 +++--- src/Web/Rep/Socket.hs | 1 + web-rep.cabal | 2 +- 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 062f9c9..d957266 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,10 @@ -0.12 +0.12.1 === +* Changed the order of Page elements, so that inline css over-rides libraries. +* Added cssColorScheme to API +0.12 +=== * markupInput replaces inputToHtml as per markup-parse * ToByteString introduced * upgrade to box-socket-0.5 diff --git a/src/Web/Rep.hs b/src/Web/Rep.hs index a599816..6f69969 100644 --- a/src/Web/Rep.hs +++ b/src/Web/Rep.hs @@ -34,6 +34,7 @@ module Web.Rep -- * Css Css (..), renderCss, + cssColorScheme, -- * JS Js (..), diff --git a/src/Web/Rep/Page.hs b/src/Web/Rep/Page.hs index 75de5c4..de64e31 100644 --- a/src/Web/Rep/Page.hs +++ b/src/Web/Rep/Page.hs @@ -15,6 +15,7 @@ module Web.Rep.Page PageStructure (..), Css (..), renderCss, + cssColorScheme, Js (..), onLoad, ) @@ -132,6 +133,27 @@ renderCss :: RenderStyle -> Css -> ByteString renderCss Compact = C.filter (\c -> c /= ' ' && c /= '\n') . cssByteString renderCss _ = cssByteString +-- | Css snippet for reponsiveness to preferred color-scheme. +cssColorScheme :: Css +cssColorScheme = + Css + [i| +{ + color-scheme: light dark; +} +{ + body { + background-color: rgb(92%, 92%, 92%); + color: rgb(5%, 5%, 5%); + } +} +@media (prefers-color-scheme:dark) { + body { + background-color: rgb(5%, 5%, 5%); + color: rgb(92%, 92%, 92%); + } +}|] + -- | Javascript as string newtype Js = Js {jsByteString :: ByteString} deriving (Eq, Show, Generic, Semigroup, Monoid) diff --git a/src/Web/Rep/Render.hs b/src/Web/Rep/Render.hs index 3f846e4..9e51ab1 100644 --- a/src/Web/Rep/Render.hs +++ b/src/Web/Rep/Render.hs @@ -50,8 +50,8 @@ renderPageWith pc p = "head" [] (element_ "meta" [Attr "charset" "utf-8"]) - <> cssInline <> libsCss' + <> cssInline <> view #htmlHeader p ) <> element @@ -71,8 +71,8 @@ renderPageWith pc p = <> libsJs' <> jsInline Snippet -> - libsCss' - <> cssInline + cssInline + <> libsCss' <> view #htmlHeader p <> view #htmlBody p <> libsJs' diff --git a/src/Web/Rep/Socket.hs b/src/Web/Rep/Socket.hs index 48e1ba6..4b516f2 100644 --- a/src/Web/Rep/Socket.hs +++ b/src/Web/Rep/Socket.hs @@ -87,6 +87,7 @@ defaultSocketPage :: Page defaultSocketPage = bootstrapPage <> socketPage + & set #cssBody cssColorScheme & set #htmlBody ( element diff --git a/web-rep.cabal b/web-rep.cabal index 495a037..21d3d23 100644 --- a/web-rep.cabal +++ b/web-rep.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: web-rep -version: 0.12.0.0 +version: 0.12.1.0 license: BSD-3-Clause license-file: LICENSE copyright: Tony Day (c) 2015