Cleanup
This commit is contained in:
parent
0f6dcbab1c
commit
103a729508
@ -1,6 +1,6 @@
|
|||||||
cabal-version: 3.0
|
cabal-version: 3.0
|
||||||
name: sampu
|
name: sampu
|
||||||
version: 0.1.0
|
version: 0.2.0
|
||||||
license: ISC
|
license: ISC
|
||||||
author: James Eversole
|
author: James Eversole
|
||||||
maintainer: james@eversole.co
|
maintainer: james@eversole.co
|
||||||
|
@ -5,7 +5,7 @@ import Configuration.Dotenv
|
|||||||
import System.Directory (doesFileExist)
|
import System.Directory (doesFileExist)
|
||||||
import System.Environment (getEnv, lookupEnv)
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
reqEnvLookup <- getRequiredEnv
|
reqEnvLookup <- getRequiredEnv
|
||||||
|
@ -13,7 +13,7 @@ import System.FilePath ( takeFileName )
|
|||||||
|
|
||||||
import Web.Twain
|
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 :: [FilePath] -> IO ()
|
||||||
main postNames = do
|
main postNames = do
|
||||||
port <- Conf.appPort
|
port <- Conf.appPort
|
||||||
@ -24,7 +24,7 @@ main postNames = do
|
|||||||
run (read port) $
|
run (read port) $
|
||||||
foldr ($) (notFound Handle.missing) app
|
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 :: [Middleware]
|
||||||
preProcessors = [ logStdoutDev
|
preProcessors = [ logStdoutDev
|
||||||
, staticPolicy $ noDots >-> addBase "data/assets/public"
|
, staticPolicy $ noDots >-> addBase "data/assets/public"
|
||||||
@ -34,7 +34,9 @@ preProcessors = [ logStdoutDev
|
|||||||
postProcessors :: [Middleware]
|
postProcessors :: [Middleware]
|
||||||
postProcessors = []
|
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 :: [FilePath] -> [Middleware]
|
||||||
routes postNames =
|
routes postNames =
|
||||||
[ get "/" Handle.index
|
[ get "/" Handle.index
|
||||||
|
@ -9,23 +9,6 @@ import Control.Monad.IO.Class (liftIO)
|
|||||||
import Lucid (Html)
|
import Lucid (Html)
|
||||||
import Web.Twain
|
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 :: ResponderM a
|
||||||
contact = do
|
contact = do
|
||||||
title <- liftIO Conf.appTitle
|
title <- liftIO Conf.appTitle
|
||||||
@ -37,8 +20,26 @@ feed = do
|
|||||||
title <- liftIO Conf.appTitle
|
title <- liftIO Conf.appTitle
|
||||||
sendLucidFragment $ basePage title baseFeed
|
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 :: ResponderM a
|
||||||
missing = sendLucidFragment pageNotFound
|
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 :: Html () -> ResponderM a
|
||||||
sendLucidFragment x = send $ html $ lucidToTwain x
|
sendLucidFragment x = send $ html $ lucidToTwain x
|
||||||
|
@ -6,14 +6,25 @@ import Data.Text
|
|||||||
import Data.String (fromString)
|
import Data.String (fromString)
|
||||||
import Lucid
|
import Lucid
|
||||||
|
|
||||||
|
baseContact :: Html () -> Html ()
|
||||||
|
baseContact content = div_ [class_ "main"] content
|
||||||
|
|
||||||
baseDoc :: String -> Html () -> Html ()
|
baseDoc :: String -> Html () -> Html ()
|
||||||
baseDoc title bodyContent = doctypehtml_ $ do
|
baseDoc title bodyContent = doctypehtml_ $ do
|
||||||
head_ $ do
|
head_ $ do
|
||||||
|
meta_ [ name_ "viewport", content_ "width=device-width, initial-scale=1.0" ]
|
||||||
title_ $ fromString title
|
title_ $ fromString title
|
||||||
link_ [rel_ "stylesheet", type_ "text/css", href_ "/style.css"]
|
link_ [rel_ "stylesheet", type_ "text/css", href_ "/style.css"]
|
||||||
-- script_ [src_ "/htmx.min.js"] none
|
|
||||||
body_ bodyContent
|
body_ bodyContent
|
||||||
|
|
||||||
|
baseFeed :: Html ()
|
||||||
|
baseFeed = div_ [class_ "main"] $ do
|
||||||
|
h2_ "Oops, I haven't been implemented yet."
|
||||||
|
h3_ "Check back in a couple days!"
|
||||||
|
|
||||||
|
baseHome :: Html () -> Html ()
|
||||||
|
baseHome content = div_ [class_ "main"] content
|
||||||
|
|
||||||
baseNav :: Html ()
|
baseNav :: Html ()
|
||||||
baseNav = div_ [class_ "navContainer"] $ do
|
baseNav = div_ [class_ "navContainer"] $ do
|
||||||
ul_ [class_ "mainNav"] $ do
|
ul_ [class_ "mainNav"] $ do
|
||||||
@ -25,9 +36,6 @@ baseNav = div_ [class_ "navContainer"] $ do
|
|||||||
basePage :: String -> Html () -> Html()
|
basePage :: String -> Html () -> Html()
|
||||||
basePage title body = baseDoc title $ baseNav <> body
|
basePage title body = baseDoc title $ baseNav <> body
|
||||||
|
|
||||||
baseHome :: Html () -> Html ()
|
|
||||||
baseHome content = div_ [class_ "main"] content
|
|
||||||
|
|
||||||
basePost :: Html () -> Html ()
|
basePost :: Html () -> Html ()
|
||||||
basePost content = div_ [class_ "main"] content
|
basePost content = div_ [class_ "main"] content
|
||||||
|
|
||||||
@ -39,13 +47,5 @@ postIndex postNames = div_ [class_ "main"] $ do
|
|||||||
(\x -> li_ $ a_ [href_ (pack $ "/posts/" ++ x)] (fromString x))
|
(\x -> li_ $ a_ [href_ (pack $ "/posts/" ++ x)] (fromString x))
|
||||||
postNames
|
postNames
|
||||||
|
|
||||||
baseContact :: Html () -> Html ()
|
|
||||||
baseContact content = div_ [class_ "main"] content
|
|
||||||
|
|
||||||
baseFeed :: Html ()
|
|
||||||
baseFeed = div_ [class_ "main"] $ do
|
|
||||||
h2_ "Oops, I haven't been implemented yet."
|
|
||||||
h3_ "Check back in a couple days!"
|
|
||||||
|
|
||||||
none :: Text
|
none :: Text
|
||||||
none = mempty
|
none = mempty
|
||||||
|
@ -13,9 +13,11 @@ main :: IO ()
|
|||||||
main = do
|
main = do
|
||||||
Conf.main
|
Conf.main
|
||||||
mdFilePaths <- getMdFilePaths "./data/posts/"
|
mdFilePaths <- getMdFilePaths "./data/posts/"
|
||||||
|
-- Pass only the post names extracted from their filepath to HTTP.main
|
||||||
let mdFiles = map (dropExtension . takeFileName) mdFilePaths
|
let mdFiles = map (dropExtension . takeFileName) mdFilePaths
|
||||||
HTTP.main mdFiles
|
HTTP.main mdFiles
|
||||||
|
|
||||||
|
-- Return a list of all non-hidden .md files except for home.md and contact.md
|
||||||
getMdFilePaths :: FilePath -> IO [FilePath]
|
getMdFilePaths :: FilePath -> IO [FilePath]
|
||||||
getMdFilePaths fp = find isVisible fileFilter fp
|
getMdFilePaths fp = find isVisible fileFilter fp
|
||||||
where
|
where
|
||||||
|
Loading…
x
Reference in New Issue
Block a user