Add default footer; further cleanup
This commit is contained in:
@ -38,12 +38,14 @@ postProcessors = []
|
||||
automatically build an index of posts available to view. -}
|
||||
routes :: [FilePath] -> [Middleware]
|
||||
routes postNames =
|
||||
[ get "/" Handle.index
|
||||
, get "/posts" $ Handle.postsIndex postNames
|
||||
] ++ (buildMdRoutes postNames) ++
|
||||
[ get "/contact" Handle.contact
|
||||
, get "/feed" $ Handle.feed postNames
|
||||
]
|
||||
[ get "/" Handle.index
|
||||
, get "/posts" $ Handle.postsIndex postNames
|
||||
] ++ handleDynamicPosts ++
|
||||
[ get "/contact" Handle.contact
|
||||
, get "/feed" $ Handle.feed postNames
|
||||
, get "/atom.xml" $ Handle.feed postNames
|
||||
] where
|
||||
handleDynamicPosts = (buildMdRoutes postNames)
|
||||
|
||||
-- Takes a post's name extracted from the filepath and returns a valid route
|
||||
mdFileToRoute :: FilePath -> Middleware
|
||||
|
@ -20,24 +20,28 @@ import Web.Twain
|
||||
index :: ResponderM a
|
||||
index = do
|
||||
-- Query the system environment for the BLOGTITLE environment variable
|
||||
title <- liftIO Conf.appTitle
|
||||
title <- liftIO Conf.appTitle
|
||||
-- Read a Commonmark Markdown file and process it to HTML
|
||||
homeMd <- liftIO $ mdFileToLucid "./data/posts/home.md"
|
||||
homeMd <- liftIO $ mdFileToLucid "./data/posts/home.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
|
||||
sendLucidFragment $ basePage title (baseHome homeMd)
|
||||
sendLucidFragment $ basePage title (baseHome homeMd) footerMd
|
||||
|
||||
-- Responds with processed Commonmark -> HTML for posts existing at app init
|
||||
posts :: FilePath -> ResponderM a
|
||||
posts postName = do
|
||||
title <- liftIO Conf.appTitle
|
||||
postMd <- liftIO $ mdFileToLucid ("./data/posts/" ++ postName ++ ".md")
|
||||
sendLucidFragment $ basePage title (basePost postMd)
|
||||
title <- liftIO Conf.appTitle
|
||||
footerMd <- liftIO $ mdFileToLucid "./data/posts/footer.md"
|
||||
postMd <- liftIO $ mdFileToLucid ("./data/posts/" ++ postName ++ ".md")
|
||||
sendLucidFragment $ basePage title (basePost postMd) footerMd
|
||||
|
||||
-- Builds an index of all posts on filesystem as of application init
|
||||
postsIndex :: [FilePath] -> ResponderM a
|
||||
postsIndex postNames = do
|
||||
title <- liftIO Conf.appTitle
|
||||
sendLucidFragment $ basePage title (postIndex postNames)
|
||||
title <- liftIO Conf.appTitle
|
||||
footerMd <- liftIO $ mdFileToLucid "./data/posts/footer.md"
|
||||
sendLucidFragment $ basePage title (postIndex postNames) footerMd
|
||||
|
||||
-- Generates the XML feed at /feed
|
||||
feed :: [FilePath] -> ResponderM a
|
||||
@ -75,7 +79,8 @@ contact :: ResponderM a
|
||||
contact = do
|
||||
title <- liftIO Conf.appTitle
|
||||
contactMd <- liftIO $ mdFileToLucid "./data/posts/contact.md"
|
||||
sendLucidFragment $ basePage title (baseContact contactMd)
|
||||
footerMd <- liftIO $ mdFileToLucid "./data/posts/footer.md"
|
||||
sendLucidFragment $ basePage title (baseContact contactMd) footerMd
|
||||
|
||||
|
||||
-- Helper function for responding in ResponderM from Html
|
||||
|
@ -15,10 +15,9 @@ baseDoc title bodyContent = doctypehtml_ $ do
|
||||
link_ [rel_ "stylesheet", type_ "text/css", href_ "/style.css"]
|
||||
body_ bodyContent
|
||||
|
||||
baseFeed :: Html ()
|
||||
baseFeed = div_ [class_ "main"] $ do
|
||||
h2_ "Oops, I haven't been implemented yet."
|
||||
h3_ "Check back in a couple days!"
|
||||
baseFooter :: Html () -> Html ()
|
||||
baseFooter content = footer_ $ do
|
||||
p_ $ content
|
||||
|
||||
baseHome :: Html () -> Html ()
|
||||
baseHome content = div_ [class_ "main"] content
|
||||
@ -31,8 +30,8 @@ baseNav = div_ [class_ "navContainer"] $ do
|
||||
li_ $ a_ [href_ "/contact"] "Contact"
|
||||
li_ $ a_ [href_ "/feed"] "Feed"
|
||||
|
||||
basePage :: String -> Html () -> Html()
|
||||
basePage title body = baseDoc title $ baseNav <> body
|
||||
basePage :: String -> Html () -> Html () -> Html ()
|
||||
basePage title body footer = baseDoc title $ baseNav <> body <> baseFooter footer
|
||||
|
||||
basePost :: Html () -> Html ()
|
||||
basePost content = div_ [class_ "main"] content
|
||||
|
15
src/Main.hs
15
src/Main.hs
@ -21,8 +21,13 @@ main = do
|
||||
getMdFilePaths :: FilePath -> IO [FilePath]
|
||||
getMdFilePaths fp = find isVisible fileFilter fp
|
||||
where
|
||||
isMdFile = extension ==? ".md"
|
||||
isVisible = fileName /~? ".?*"
|
||||
isHome = fileName /~? "home.md"
|
||||
isContact = fileName /~? "contact.md"
|
||||
fileFilter = isMdFile &&? isVisible &&? isHome &&? isContact
|
||||
isMdFile = extension ==? ".md"
|
||||
isVisible = fileName /~? ".?*"
|
||||
isHome = fileName /~? "home.md"
|
||||
isContact = fileName /~? "contact.md"
|
||||
isFooter = fileName /~? "footer.md"
|
||||
fileFilter = isMdFile
|
||||
&&? isVisible
|
||||
&&? isHome
|
||||
&&? isContact
|
||||
&&? isFooter
|
||||
|
Reference in New Issue
Block a user