This commit is contained in:
2024-02-24 13:10:48 -06:00
parent 0f6dcbab1c
commit 103a729508
6 changed files with 39 additions and 34 deletions

View File

@ -5,7 +5,7 @@ import Configuration.Dotenv
import System.Directory (doesFileExist)
import System.Environment (getEnv, lookupEnv)
-- Load environment variables from dotenv file if required
-- Load environment variables from dotenv file if any are missing from ENV
main :: IO ()
main = do
reqEnvLookup <- getRequiredEnv

View File

@ -13,7 +13,7 @@ import System.FilePath ( takeFileName )
import Web.Twain
-- Get the port to listen on from the ENV and start the webserver
-- Get the port to listen on from the ENV and start the webserver.
main :: [FilePath] -> IO ()
main postNames = do
port <- Conf.appPort
@ -24,7 +24,7 @@ main postNames = do
run (read port) $
foldr ($) (notFound Handle.missing) app
-- These Middlewares are executed before any routes are reached
-- These Middlewares are executed before any routes are reached.
preProcessors :: [Middleware]
preProcessors = [ logStdoutDev
, staticPolicy $ noDots >-> addBase "data/assets/public"
@ -34,7 +34,9 @@ preProcessors = [ logStdoutDev
postProcessors :: [Middleware]
postProcessors = []
-- The application's core routes expressed as a list of WAI Middlewares
{- The application's core routes expressed as a list of WAI Middlewares.
The list of post names is required so that the postsIndex handler can
automatically build an index of posts available to view. -}
routes :: [FilePath] -> [Middleware]
routes postNames =
[ get "/" Handle.index

View File

@ -9,23 +9,6 @@ import Control.Monad.IO.Class (liftIO)
import Lucid (Html)
import Web.Twain
index :: ResponderM a
index = do
title <- liftIO Conf.appTitle
homeMd <- liftIO $ mdFileToLucid "./data/posts/home.md"
sendLucidFragment $ basePage title (baseHome homeMd)
postsIndex :: [FilePath] -> ResponderM a
postsIndex postNames = do
title <- liftIO Conf.appTitle
sendLucidFragment $ basePage title (postIndex postNames)
posts :: FilePath -> ResponderM a
posts postName = do
title <- liftIO Conf.appTitle
postMd <- liftIO $ mdFileToLucid ("./data/posts/" ++ postName ++ ".md")
sendLucidFragment $ basePage title (basePost postMd)
contact :: ResponderM a
contact = do
title <- liftIO Conf.appTitle
@ -37,8 +20,26 @@ feed = do
title <- liftIO Conf.appTitle
sendLucidFragment $ basePage title baseFeed
index :: ResponderM a
index = do
title <- liftIO Conf.appTitle
homeMd <- liftIO $ mdFileToLucid "./data/posts/home.md"
sendLucidFragment $ basePage title (baseHome homeMd)
missing :: ResponderM a
missing = sendLucidFragment pageNotFound
posts :: FilePath -> ResponderM a
posts postName = do
title <- liftIO Conf.appTitle
postMd <- liftIO $ mdFileToLucid ("./data/posts/" ++ postName ++ ".md")
sendLucidFragment $ basePage title (basePost postMd)
postsIndex :: [FilePath] -> ResponderM a
postsIndex postNames = do
title <- liftIO Conf.appTitle
sendLucidFragment $ basePage title (postIndex postNames)
-- Helper function for responding in ResponderM from Html
sendLucidFragment :: Html () -> ResponderM a
sendLucidFragment x = send $ html $ lucidToTwain x