add current time to site
This commit is contained in:
parent
b72a64bf08
commit
58932cd930
2 changed files with 15 additions and 10 deletions
24
src/Main.hs
24
src/Main.hs
|
@ -4,8 +4,8 @@ import Data.Monoid ((<>))
|
||||||
import Hakyll
|
import Hakyll
|
||||||
-- import Hakyll.Web.Sass
|
-- import Hakyll.Web.Sass
|
||||||
|
|
||||||
import Data.Time.Clock (UTCTime)
|
import Data.Time.Clock (UTCTime, getCurrentTime)
|
||||||
import Data.Time.Format (parseTimeM, defaultTimeLocale)
|
import Data.Time.Format (parseTimeM, defaultTimeLocale, formatTime)
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import System.FilePath (takeFileName)
|
import System.FilePath (takeFileName)
|
||||||
|
@ -18,7 +18,11 @@ baseUrl :: String
|
||||||
baseUrl = "https://chaoszone.cz"
|
baseUrl = "https://chaoszone.cz"
|
||||||
|
|
||||||
main :: IO ()
|
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"
|
is <- sortIdentifiersByDate <$> getMatches "site/posts/*.md"
|
||||||
|
|
||||||
|
@ -49,7 +53,7 @@ main = hakyllWith config $ do
|
||||||
pandocCompiler
|
pandocCompiler
|
||||||
>>= loadAndApplyTemplate "templates/default.html"
|
>>= loadAndApplyTemplate "templates/default.html"
|
||||||
-- (menuCtx firstUrl latestUrl)
|
-- (menuCtx firstUrl latestUrl)
|
||||||
defaultContext
|
defaultCtx
|
||||||
>>= relativizeUrls
|
>>= relativizeUrls
|
||||||
|
|
||||||
match "site/index.md" $ do
|
match "site/index.md" $ do
|
||||||
|
@ -58,11 +62,11 @@ main = hakyllWith config $ do
|
||||||
posts <- fmap (take 5) . recentFirst =<< loadAll "site/posts/*"
|
posts <- fmap (take 5) . recentFirst =<< loadAll "site/posts/*"
|
||||||
let indexCtx = listField "posts" postCtx (return posts) <>
|
let indexCtx = listField "posts" postCtx (return posts) <>
|
||||||
constField "title" "Home" <>
|
constField "title" "Home" <>
|
||||||
defaultContext
|
defaultCtx
|
||||||
getResourceBody
|
getResourceBody
|
||||||
>>= applyAsTemplate indexCtx
|
>>= applyAsTemplate indexCtx
|
||||||
>>= renderPandoc
|
>>= renderPandoc
|
||||||
>>= loadAndApplyTemplate "templates/default.html" defaultContext
|
>>= loadAndApplyTemplate "templates/default.html" defaultCtx
|
||||||
>>= relativizeUrls
|
>>= relativizeUrls
|
||||||
|
|
||||||
create ["archive.html"] $ do
|
create ["archive.html"] $ do
|
||||||
|
@ -75,7 +79,7 @@ main = hakyllWith config $ do
|
||||||
listField "posts" postCtx (return posts) <>
|
listField "posts" postCtx (return posts) <>
|
||||||
constField "title" "Archives" <>
|
constField "title" "Archives" <>
|
||||||
-- (menuCtx firstUrl latestUrl)
|
-- (menuCtx firstUrl latestUrl)
|
||||||
defaultContext
|
defaultCtx
|
||||||
makeItem ""
|
makeItem ""
|
||||||
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
|
>>= loadAndApplyTemplate "templates/archive.html" archiveCtx
|
||||||
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
|
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
|
||||||
|
@ -102,7 +106,7 @@ main = hakyllWith config $ do
|
||||||
full <- loadAndApplyTemplate "templates/post.html" ctx compiled
|
full <- loadAndApplyTemplate "templates/post.html" ctx compiled
|
||||||
_ <- saveSnapshot "content" compiled
|
_ <- saveSnapshot "content" compiled
|
||||||
loadAndApplyTemplate "templates/default.html"
|
loadAndApplyTemplate "templates/default.html"
|
||||||
defaultContext full
|
defaultCtx full
|
||||||
>>= relativizeUrls
|
>>= relativizeUrls
|
||||||
|
|
||||||
-- create ["index.html"] $ do
|
-- create ["index.html"] $ do
|
||||||
|
@ -111,7 +115,7 @@ main = hakyllWith config $ do
|
||||||
-- post <- fmap head . recentFirst =<< (loadAll "site/posts/*" :: Compiler [Item String])
|
-- post <- fmap head . recentFirst =<< (loadAll "site/posts/*" :: Compiler [Item String])
|
||||||
-- let indexCtx =
|
-- let indexCtx =
|
||||||
-- constField "date" "%B %e, %Y" <>
|
-- constField "date" "%B %e, %Y" <>
|
||||||
-- defaultContext
|
-- defaultCtx
|
||||||
-- makeItem (itemBody post)
|
-- makeItem (itemBody post)
|
||||||
-- >>= relativizeUrls
|
-- >>= relativizeUrls
|
||||||
|
|
||||||
|
@ -130,7 +134,7 @@ postCtx =
|
||||||
-- menuCtx first latest =
|
-- menuCtx first latest =
|
||||||
-- constField "first" first <>
|
-- constField "first" first <>
|
||||||
-- constField "latest" latest <>
|
-- constField "latest" latest <>
|
||||||
-- defaultContext
|
-- defaultCtx
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
config :: Configuration
|
config :: Configuration
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer id="footer">
|
<footer id="footer">
|
||||||
|
last updated on: $curtime$ |
|
||||||
Site proudly generated by
|
Site proudly generated by
|
||||||
<a href="http://jaspervdj.be/hakyll">Hakyll</a>
|
<a href="http://jaspervdj.be/hakyll">Hakyll</a>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
Loading…
Reference in a new issue