From e6f4ca04ba1e8a8f2ae299e5a2ec09f26a89e736 Mon Sep 17 00:00:00 2001 From: Carlos Sosa Date: Sun, 11 Aug 2019 17:18:45 -0700 Subject: Add log entries, and move to better context functions --- site.hs | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'site.hs') diff --git a/site.hs b/site.hs index b980948..1913d6f 100644 --- a/site.hs +++ b/site.hs @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- {-# LANGUAGE OverloadedStrings #-} -import Data.Monoid (mappend) +import Data.Monoid ((<>)) import Hakyll @@ -21,51 +21,55 @@ main = hakyll $ do >>= loadAndApplyTemplate "templates/default.html" defaultContext >>= relativizeUrls - match "log/*.markdown" $ do + match "log/*.org" $ do route $ setExtension "html" compile $ pandocCompiler - >>= loadAndApplyTemplate "templates/post.html" postCtx + >>= loadAndApplyTemplate "templates/post.html" postCtx >>= relativizeUrls create ["log/index.html"] $ do route idRoute compile $ do - posts <- recentFirst =<< loadAll "log/*.markdown" - let archiveCtx = - listField "posts" postForArchiveCtx (return posts) `mappend` - constField "title" "archive of log posts" `mappend` - defaultContext - makeItem "" - >>= loadAndApplyTemplate "templates/archive.html" archiveCtx + >>= loadAndApplyTemplate "templates/archive.html" postForArchiveCtx >>= loadAndApplyTemplate "templates/post.html" archiveCtx >>= relativizeUrls - match "index.html" $ do route idRoute compile $ do - posts <- recentFirst =<< loadAll "posts/*" - let indexCtx = - listField "posts" postCtx (return posts) `mappend` - constField "title" "Home" `mappend` - defaultContext - - getResourceBody - >>= applyAsTemplate indexCtx - >>= loadAndApplyTemplate "templates/default.html" indexCtx - >>= relativizeUrls + getResourceBody + >>= applyAsTemplate indexCtx + >>= loadAndApplyTemplate "templates/default.html" indexCtx + >>= relativizeUrls match "templates/*" $ compile templateBodyCompiler -------------------------------------------------------------------------------- +posts :: Compiler [Item String] +posts = recentFirst =<< loadAll "log/*.org" + +indexCtx :: Context String +indexCtx = + listField "posts" postCtx posts <> + constField "title" "Home" <> + defaultContext + +archiveCtx :: Context String +archiveCtx = + constField "title" "archive of log posts" <> + defaultContext + postCtx :: Context String postCtx = - dateField "date" "%B %e, %Y" `mappend` - defaultContext + dateField "date" "%B %e, %Y" <> defaultContext postForArchiveCtx :: Context String postForArchiveCtx = - dateField "date" "%d %b %Y" `mappend` + listField "posts" dateForArchiveCtx posts <> defaultContext + +dateForArchiveCtx :: Context String +dateForArchiveCtx = + dateField "date" "%d %b %Y" <> defaultContext -- cgit v1.3-2-g0d8e