Working on adding blog post lookups.
authorsabadev <saba@sabadev.xyz>
Tue, 16 Mar 2021 21:59:13 +0000 (17:59 -0400)
committersabadev <dev@sabadev.xyz>
Tue, 13 Apr 2021 01:16:10 +0000 (21:16 -0400)
.gitignore
src/Server.hs

index ae1a9aa..82c9e92 100644 (file)
@@ -2,3 +2,4 @@
 *~
 tags*
 .vagrant/
+static/
index dc04496..4af5b38 100644 (file)
@@ -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