|
|
|
@ -4,7 +4,6 @@ import qualified Core.Configuration as Conf
|
|
|
|
|
import Core.Feed (Post(..), autoFeed, renderFeed)
|
|
|
|
|
import Core.Rendering
|
|
|
|
|
import Fragments.Base
|
|
|
|
|
import Fragments.NotFound
|
|
|
|
|
import Fragments.Styles as S
|
|
|
|
|
|
|
|
|
|
import qualified Text.Atom.Feed as Atom
|
|
|
|
@ -23,14 +22,12 @@ import Web.Twain hiding (fileName)
|
|
|
|
|
-- A ResponoderM capable of lifting to IO monad; constructs response to clients
|
|
|
|
|
index :: ResponderM a
|
|
|
|
|
index = do
|
|
|
|
|
-- Query the system environment for the BLOGTITLE environment variable
|
|
|
|
|
title <- liftIO Conf.title
|
|
|
|
|
-- Read a Commonmark Markdown file and process it to HTML
|
|
|
|
|
homeMd <- liftIO $ mdFileToLucid "./data/posts/home.md"
|
|
|
|
|
-- Get the Footer content from Markdown
|
|
|
|
|
footerMd <- liftIO $ mdFileToLucid "./data/posts/footer.md"
|
|
|
|
|
(title, homeMd, footerMd) <- liftIO $ (,,)
|
|
|
|
|
<$> Conf.title
|
|
|
|
|
<*> mdFileToLucid "./data/posts/home.md"
|
|
|
|
|
<*> mdFileToLucid "./data/posts/footer.md"
|
|
|
|
|
-- Respond to request with fragments compositionally to create a home page
|
|
|
|
|
sendLucidFragment $ basePage title (baseHome homeMd) footerMd
|
|
|
|
|
sendLucidFragment $ basePage title (baseHome homeMd) footerMd
|
|
|
|
|
|
|
|
|
|
-- Responds with processed Commonmark -> HTML for posts
|
|
|
|
|
posts :: ResponderM a
|
|
|
|
@ -40,10 +37,11 @@ posts = do
|
|
|
|
|
case postValid of
|
|
|
|
|
False -> missing
|
|
|
|
|
True -> do
|
|
|
|
|
title <- liftIO Conf.title
|
|
|
|
|
footerMd <- liftIO $ mdFileToLucid "./data/posts/footer.md"
|
|
|
|
|
postMd <- liftIO $ mdFileToLucid $ postPath postName
|
|
|
|
|
sendLucidFragment $ basePage title (basePost postMd) footerMd
|
|
|
|
|
(title, footerMd, postMd) <- liftIO $ (,,)
|
|
|
|
|
<$> Conf.title
|
|
|
|
|
<*> mdFileToLucid "./data/posts/footer.md"
|
|
|
|
|
<*> (mdFileToLucid $ postPath postName)
|
|
|
|
|
sendLucidFragment $ basePage title (basePost postMd) footerMd
|
|
|
|
|
where
|
|
|
|
|
postExists :: T.Text -> IO Bool
|
|
|
|
|
postExists postName = doesFileExist $ postPath postName
|
|
|
|
@ -54,20 +52,21 @@ posts = do
|
|
|
|
|
-- Builds an index of all posts
|
|
|
|
|
postsIndex :: ResponderM a
|
|
|
|
|
postsIndex = do
|
|
|
|
|
postNames <- liftIO mdPostNames
|
|
|
|
|
title <- liftIO Conf.title
|
|
|
|
|
footerMd <- liftIO $ mdFileToLucid "./data/posts/footer.md"
|
|
|
|
|
sendLucidFragment $ basePage title (postIndex postNames) footerMd
|
|
|
|
|
(postNames, title, footerMd) <- liftIO $ (,,)
|
|
|
|
|
<$> mdPostNames
|
|
|
|
|
<*> Conf.title
|
|
|
|
|
<*> mdFileToLucid "./data/posts/footer.md"
|
|
|
|
|
sendLucidFragment $ basePage title (postIndex postNames) footerMd
|
|
|
|
|
|
|
|
|
|
-- Generates the XML feed at /feed
|
|
|
|
|
feed :: ResponderM a
|
|
|
|
|
feed = do
|
|
|
|
|
postNames <- liftIO mdPostNames
|
|
|
|
|
title <- liftIO Conf.title
|
|
|
|
|
baseUrl <- liftIO Conf.baseUrl
|
|
|
|
|
time <- liftIO $ fmap (\x -> timeFormat x) getCurrentTime
|
|
|
|
|
-- Create Atom [Post] to populate the feed
|
|
|
|
|
feedData <- liftIO $ mapM (makePost baseUrl) postNames
|
|
|
|
|
(postNames, title, baseUrl, time) <- liftIO $ (,,,)
|
|
|
|
|
<$> mdPostNames
|
|
|
|
|
<*> Conf.title
|
|
|
|
|
<*> Conf.baseUrl
|
|
|
|
|
<*> fmap (\x -> timeFormat x) getCurrentTime
|
|
|
|
|
feedData <- liftIO $ mapM (makePost baseUrl) postNames
|
|
|
|
|
-- Send an XML response with an automatically populated Atom feed
|
|
|
|
|
send $ xml $ TLE.encodeUtf8 $ renderFeed
|
|
|
|
|
$ autoFeed (baseFeed title time baseUrl) feedData
|
|
|
|
@ -97,9 +96,10 @@ feed = do
|
|
|
|
|
-- Refer to index comments
|
|
|
|
|
contact :: ResponderM a
|
|
|
|
|
contact = do
|
|
|
|
|
title <- liftIO Conf.title
|
|
|
|
|
contactMd <- liftIO $ mdFileToLucid "./data/posts/contact.md"
|
|
|
|
|
footerMd <- liftIO $ mdFileToLucid "./data/posts/footer.md"
|
|
|
|
|
(title, contactMd, footerMd) <- liftIO $ (,,)
|
|
|
|
|
<$> Conf.title
|
|
|
|
|
<*> mdFileToLucid "./data/posts/contact.md"
|
|
|
|
|
<*> mdFileToLucid "./data/posts/footer.md"
|
|
|
|
|
sendLucidFragment $ basePage title (baseContact contactMd) footerMd
|
|
|
|
|
|
|
|
|
|
-- Respond with primary processed CSS
|
|
|
|
|