From 58932cd9305c39569bdead912007215fa9629c0a Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 10 Nov 2017 14:07:48 +0100 Subject: [PATCH] add current time to site --- src/Main.hs | 24 ++++++++++++++---------- templates/default.html | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 7bf1e38..0ec172f 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -4,8 +4,8 @@ import Data.Monoid ((<>)) import Hakyll -- import Hakyll.Web.Sass -import Data.Time.Clock (UTCTime) -import Data.Time.Format (parseTimeM, defaultTimeLocale) +import Data.Time.Clock (UTCTime, getCurrentTime) +import Data.Time.Format (parseTimeM, defaultTimeLocale, formatTime) import Data.List import Data.Maybe (fromMaybe) import System.FilePath (takeFileName) @@ -18,7 +18,11 @@ baseUrl :: String baseUrl = "https://chaoszone.cz" main :: IO () -main = hakyllWith config $ do +main = do + curtime <- formatTime defaultTimeLocale "%A %F %H:%M" <$> getCurrentTime + hakyllWith config $ do + + let defaultCtx = constField "curtime" curtime <> defaultContext is <- sortIdentifiersByDate <$> getMatches "site/posts/*.md" @@ -49,7 +53,7 @@ main = hakyllWith config $ do pandocCompiler >>= loadAndApplyTemplate "templates/default.html" -- (menuCtx firstUrl latestUrl) - defaultContext + defaultCtx >>= relativizeUrls match "site/index.md" $ do @@ -58,11 +62,11 @@ main = hakyllWith config $ do posts <- fmap (take 5) . recentFirst =<< loadAll "site/posts/*" let indexCtx = listField "posts" postCtx (return posts) <> constField "title" "Home" <> - defaultContext + defaultCtx getResourceBody >>= applyAsTemplate indexCtx >>= renderPandoc - >>= loadAndApplyTemplate "templates/default.html" defaultContext + >>= loadAndApplyTemplate "templates/default.html" defaultCtx >>= relativizeUrls create ["archive.html"] $ do @@ -75,7 +79,7 @@ main = hakyllWith config $ do listField "posts" postCtx (return posts) <> constField "title" "Archives" <> -- (menuCtx firstUrl latestUrl) - defaultContext + defaultCtx makeItem "" >>= loadAndApplyTemplate "templates/archive.html" archiveCtx >>= loadAndApplyTemplate "templates/default.html" archiveCtx @@ -102,7 +106,7 @@ main = hakyllWith config $ do full <- loadAndApplyTemplate "templates/post.html" ctx compiled _ <- saveSnapshot "content" compiled loadAndApplyTemplate "templates/default.html" - defaultContext full + defaultCtx full >>= relativizeUrls -- create ["index.html"] $ do @@ -111,7 +115,7 @@ main = hakyllWith config $ do -- post <- fmap head . recentFirst =<< (loadAll "site/posts/*" :: Compiler [Item String]) -- let indexCtx = -- constField "date" "%B %e, %Y" <> - -- defaultContext + -- defaultCtx -- makeItem (itemBody post) -- >>= relativizeUrls @@ -130,7 +134,7 @@ postCtx = -- menuCtx first latest = -- constField "first" first <> -- constField "latest" latest <> --- defaultContext +-- defaultCtx -------------------------------------------------------------------------------- config :: Configuration diff --git a/templates/default.html b/templates/default.html index c3fb1b9..d5a97de 100644 --- a/templates/default.html +++ b/templates/default.html @@ -33,6 +33,7 @@