From fa54723934bcc71a92c909e0de41804653fcce90 Mon Sep 17 00:00:00 2001 From: James Eversole Date: Sat, 24 Feb 2024 17:53:59 -0600 Subject: [PATCH] Add default footer; further cleanup --- data/assets/public/style.css | 40 ++++++++++++++++++++++++++++++++---- data/posts/footer.md.example | 1 + src/Core/HTTP.hs | 14 +++++++------ src/Core/Handlers.hs | 23 +++++++++++++-------- src/Fragments/Base.hs | 11 +++++----- src/Main.hs | 15 +++++++++----- 6 files changed, 74 insertions(+), 30 deletions(-) create mode 100644 data/posts/footer.md.example diff --git a/data/assets/public/style.css b/data/assets/public/style.css index 436dab8..ab0ac07 100644 --- a/data/assets/public/style.css +++ b/data/assets/public/style.css @@ -1,27 +1,52 @@ -html{font-family:Monospace;background-color:#f1f6f0;color:#222323} +html{background-color:#f1f6f0;color:#222323} a{text-decoration:none} -h2{text-transform:uppercase} -h3{margin:0.25em 0 0.25em 0} p{margin:0.4em 0 0.4em 0} a{color:#6D92AD} body { - margin: 1% 2%; + margin: 0 auto; + font-family: Monospace; font-size: 1.25em; font-weight: 300; text-align: left } +body strong { + font-weight: 600; +} + body li { list-style-type: "~> "; } +footer { + position: absolute; + margin: 0; + bottom: 0; + width: 100%; + background-color: rgba(109, 146, 173, 0.3); + text-align: center; + padding: 1em 0 0.9em 0; + box-sizing: border-box; +} + +footer p { + font-size: 0.75em; + margin: 0 2em; + color: #f1f6f0; +} + +footer p a { + color: #f1f6f0; +} + .main { margin: 1em auto; max-width: 60%; } .navContainer { + margin: 1.5em 0; width: 100%; text-align: center; } @@ -59,3 +84,10 @@ body li { .postList { font-size: 1.5em; } + +@media only screen and (max-width : 768px) { + .main { + margin: 1em auto; + max-width: 90%; + } +} diff --git a/data/posts/footer.md.example b/data/posts/footer.md.example new file mode 100644 index 0000000..ebc2ae3 --- /dev/null +++ b/data/posts/footer.md.example @@ -0,0 +1 @@ +Copyright [Your Name](youremail@address.local) diff --git a/src/Core/HTTP.hs b/src/Core/HTTP.hs index 84d301a..b77239e 100644 --- a/src/Core/HTTP.hs +++ b/src/Core/HTTP.hs @@ -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 diff --git a/src/Core/Handlers.hs b/src/Core/Handlers.hs index a712309..5cb765d 100644 --- a/src/Core/Handlers.hs +++ b/src/Core/Handlers.hs @@ -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 diff --git a/src/Fragments/Base.hs b/src/Fragments/Base.hs index 0288940..c89d28f 100644 --- a/src/Fragments/Base.hs +++ b/src/Fragments/Base.hs @@ -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 diff --git a/src/Main.hs b/src/Main.hs index 3ed4d3c..b36366c 100644 --- a/src/Main.hs +++ b/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