Clarify IO usage via Applicative interface in Handlers, whitespace cleanup, remove dedicated source file for 404 view
This commit is contained in:
parent
bf47f02282
commit
754302e543
@ -1,6 +1,6 @@
|
|||||||
# the sampu Haskell blog engine
|
# the sampu Haskell blog engine
|
||||||
|
|
||||||
https://eversole.co (not live yet!)
|
https://eversole.co
|
||||||
|
|
||||||
a _work-in-progress_ blog engine using simple flat-file Markdown content storage
|
a _work-in-progress_ blog engine using simple flat-file Markdown content storage
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
cabal-version: 3.0
|
cabal-version: 3.0
|
||||||
name: sampu
|
name: sampu
|
||||||
version: 0.9.1
|
version: 0.9.2
|
||||||
license: ISC
|
license: ISC
|
||||||
author: James Eversole
|
author: James Eversole
|
||||||
maintainer: james@eversole.co
|
maintainer: james@eversole.co
|
||||||
@ -38,6 +38,5 @@ executable sampu
|
|||||||
Core.HTTP
|
Core.HTTP
|
||||||
Core.Rendering
|
Core.Rendering
|
||||||
Fragments.Base
|
Fragments.Base
|
||||||
Fragments.NotFound
|
|
||||||
Fragments.Styles
|
Fragments.Styles
|
||||||
default-language: GHC2021
|
default-language: GHC2021
|
||||||
|
@ -4,7 +4,6 @@ import qualified Core.Configuration as Conf
|
|||||||
import Core.Feed (Post(..), autoFeed, renderFeed)
|
import Core.Feed (Post(..), autoFeed, renderFeed)
|
||||||
import Core.Rendering
|
import Core.Rendering
|
||||||
import Fragments.Base
|
import Fragments.Base
|
||||||
import Fragments.NotFound
|
|
||||||
import Fragments.Styles as S
|
import Fragments.Styles as S
|
||||||
|
|
||||||
import qualified Text.Atom.Feed as Atom
|
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
|
-- A ResponoderM capable of lifting to IO monad; constructs response to clients
|
||||||
index :: ResponderM a
|
index :: ResponderM a
|
||||||
index = do
|
index = do
|
||||||
-- Query the system environment for the BLOGTITLE environment variable
|
(title, homeMd, footerMd) <- liftIO $ (,,)
|
||||||
title <- liftIO Conf.title
|
<$> Conf.title
|
||||||
-- Read a Commonmark Markdown file and process it to HTML
|
<*> mdFileToLucid "./data/posts/home.md"
|
||||||
homeMd <- liftIO $ mdFileToLucid "./data/posts/home.md"
|
<*> mdFileToLucid "./data/posts/footer.md"
|
||||||
-- Get the Footer content from Markdown
|
|
||||||
footerMd <- liftIO $ mdFileToLucid "./data/posts/footer.md"
|
|
||||||
-- Respond to request with fragments compositionally to create a home page
|
-- 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
|
-- Responds with processed Commonmark -> HTML for posts
|
||||||
posts :: ResponderM a
|
posts :: ResponderM a
|
||||||
@ -40,10 +37,11 @@ posts = do
|
|||||||
case postValid of
|
case postValid of
|
||||||
False -> missing
|
False -> missing
|
||||||
True -> do
|
True -> do
|
||||||
title <- liftIO Conf.title
|
(title, footerMd, postMd) <- liftIO $ (,,)
|
||||||
footerMd <- liftIO $ mdFileToLucid "./data/posts/footer.md"
|
<$> Conf.title
|
||||||
postMd <- liftIO $ mdFileToLucid $ postPath postName
|
<*> mdFileToLucid "./data/posts/footer.md"
|
||||||
sendLucidFragment $ basePage title (basePost postMd) footerMd
|
<*> (mdFileToLucid $ postPath postName)
|
||||||
|
sendLucidFragment $ basePage title (basePost postMd) footerMd
|
||||||
where
|
where
|
||||||
postExists :: T.Text -> IO Bool
|
postExists :: T.Text -> IO Bool
|
||||||
postExists postName = doesFileExist $ postPath postName
|
postExists postName = doesFileExist $ postPath postName
|
||||||
@ -54,20 +52,21 @@ posts = do
|
|||||||
-- Builds an index of all posts
|
-- Builds an index of all posts
|
||||||
postsIndex :: ResponderM a
|
postsIndex :: ResponderM a
|
||||||
postsIndex = do
|
postsIndex = do
|
||||||
postNames <- liftIO mdPostNames
|
(postNames, title, footerMd) <- liftIO $ (,,)
|
||||||
title <- liftIO Conf.title
|
<$> mdPostNames
|
||||||
footerMd <- liftIO $ mdFileToLucid "./data/posts/footer.md"
|
<*> Conf.title
|
||||||
sendLucidFragment $ basePage title (postIndex postNames) footerMd
|
<*> mdFileToLucid "./data/posts/footer.md"
|
||||||
|
sendLucidFragment $ basePage title (postIndex postNames) footerMd
|
||||||
|
|
||||||
-- Generates the XML feed at /feed
|
-- Generates the XML feed at /feed
|
||||||
feed :: ResponderM a
|
feed :: ResponderM a
|
||||||
feed = do
|
feed = do
|
||||||
postNames <- liftIO mdPostNames
|
(postNames, title, baseUrl, time) <- liftIO $ (,,,)
|
||||||
title <- liftIO Conf.title
|
<$> mdPostNames
|
||||||
baseUrl <- liftIO Conf.baseUrl
|
<*> Conf.title
|
||||||
time <- liftIO $ fmap (\x -> timeFormat x) getCurrentTime
|
<*> Conf.baseUrl
|
||||||
-- Create Atom [Post] to populate the feed
|
<*> fmap (\x -> timeFormat x) getCurrentTime
|
||||||
feedData <- liftIO $ mapM (makePost baseUrl) postNames
|
feedData <- liftIO $ mapM (makePost baseUrl) postNames
|
||||||
-- Send an XML response with an automatically populated Atom feed
|
-- Send an XML response with an automatically populated Atom feed
|
||||||
send $ xml $ TLE.encodeUtf8 $ renderFeed
|
send $ xml $ TLE.encodeUtf8 $ renderFeed
|
||||||
$ autoFeed (baseFeed title time baseUrl) feedData
|
$ autoFeed (baseFeed title time baseUrl) feedData
|
||||||
@ -97,9 +96,10 @@ feed = do
|
|||||||
-- Refer to index comments
|
-- Refer to index comments
|
||||||
contact :: ResponderM a
|
contact :: ResponderM a
|
||||||
contact = do
|
contact = do
|
||||||
title <- liftIO Conf.title
|
(title, contactMd, footerMd) <- liftIO $ (,,)
|
||||||
contactMd <- liftIO $ mdFileToLucid "./data/posts/contact.md"
|
<$> Conf.title
|
||||||
footerMd <- liftIO $ mdFileToLucid "./data/posts/footer.md"
|
<*> mdFileToLucid "./data/posts/contact.md"
|
||||||
|
<*> mdFileToLucid "./data/posts/footer.md"
|
||||||
sendLucidFragment $ basePage title (baseContact contactMd) footerMd
|
sendLucidFragment $ basePage title (baseContact contactMd) footerMd
|
||||||
|
|
||||||
-- Respond with primary processed CSS
|
-- Respond with primary processed CSS
|
||||||
|
@ -44,5 +44,10 @@ postIndex postNames = div_ [class_ "postList"] $ do
|
|||||||
(\x -> li_ $ a_ [href_ (pack $ "/posts/" ++ x)] (fromString x))
|
(\x -> li_ $ a_ [href_ (pack $ "/posts/" ++ x)] (fromString x))
|
||||||
postNames
|
postNames
|
||||||
|
|
||||||
|
pageNotFound :: Html ()
|
||||||
|
pageNotFound = baseDoc "404" baseNav <>
|
||||||
|
(div_ [class_ "notFound"] $ h1_ "404 NOT FOUND")
|
||||||
|
|
||||||
none :: Text
|
none :: Text
|
||||||
none = mempty
|
none = mempty
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
module Fragments.NotFound where
|
|
||||||
|
|
||||||
import Fragments.Base
|
|
||||||
|
|
||||||
import Lucid
|
|
||||||
|
|
||||||
pageNotFound :: Html ()
|
|
||||||
pageNotFound = baseDoc "404" baseNav <>
|
|
||||||
(div_ [class_ "notFound"] $ h1_ "404 NOT FOUND")
|
|
Loading…
x
Reference in New Issue
Block a user