From 7116d156a1009d75fd19a993cbb204ec3a79dc33 Mon Sep 17 00:00:00 2001 From: sabadev Date: Tue, 16 Mar 2021 17:59:13 -0400 Subject: [PATCH] Working on adding blog post lookups. --- .gitignore | 1 + src/Server.hs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ae1a9aa..82c9e92 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *~ tags* .vagrant/ +static/ diff --git a/src/Server.hs b/src/Server.hs index dc04496..4af5b38 100644 --- a/src/Server.hs +++ b/src/Server.hs @@ -1,11 +1,13 @@ module Server where +import Control.Monad.IO.Class (liftIO) import CssContentType import Lucid import RenderBlog (renderBlog) import Servant import Servant.HTML.Lucid (HTML(..)) import qualified Data.Text as T +import qualified Data.Text.IO as T app :: Application app = serve apiProxy api @@ -32,19 +34,24 @@ mainPage = pure $ with doctypehtml_ [lang_ "en"] $ do meta_ [charset_ "utf8"] meta_ [name_ "description", content_ "width=device-width"] link_ [rel_ "stylesheet", href_ "/dark"] - body_ $ do + body_ $ div_ [role_ "main"] $ do h1_ $ toHtml siteTitle blogPost :: Maybe BlogId -> Handler (Html ()) blogPost Nothing = mainPage -blogPost (Just blogId) = mainPage +blogPost (Just blogId) = findBlogPost blogId >>= pure . renderBlog + +findBlogPost :: BlogId -> Handler T.Text +findBlogPost = liftIO . T.readFile . (<>) "/static/" themes :: Server Themes themes = darkTheme :<|> lightTheme +-- TODO Modify this endpoint to take in a single hex colour value and produce a stylesheet from it. darkTheme :: Handler T.Text darkTheme = pure mempty +-- TODO Modify this endpoint to take in a single hex colour value and produce a stylesheet from it. The strategy used here should be the inverse of the one used by the dark path. lightTheme :: Handler T.Text lightTheme = pure mempty -- 2.20.1