From b0098326cddad2437f9d4b2f30af6568acc5ca54 Mon Sep 17 00:00:00 2001 From: Carlos Sosa Date: Wed, 14 Aug 2019 23:38:25 -0700 Subject: Move to Compilers/Context as functions * Added a match for the articles category On =match "article/**"=, we create the routes via =idRoute=, and later only pass the HTML body of each entry to the compile step that also captures any metadata on the file. All of this on the =compile getResourceBody= function --- site.hs | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/site.hs b/site.hs index 1913d6f..3148518 100644 --- a/site.hs +++ b/site.hs @@ -15,12 +15,6 @@ main = hakyll $ do route idRoute compile compressCssCompiler - match (fromList ["about.rst", "contact.markdown"]) $ do - route $ setExtension "html" - compile $ pandocCompiler - >>= loadAndApplyTemplate "templates/default.html" defaultContext - >>= relativizeUrls - match "log/*.org" $ do route $ setExtension "html" compile $ pandocCompiler @@ -35,12 +29,15 @@ main = hakyll $ do >>= loadAndApplyTemplate "templates/post.html" archiveCtx >>= relativizeUrls + match "article/**" $ do + route idRoute + compile getResourceBody + match "index.html" $ do route idRoute compile $ do getResourceBody >>= applyAsTemplate indexCtx - >>= loadAndApplyTemplate "templates/default.html" indexCtx >>= relativizeUrls match "templates/*" $ compile templateBodyCompiler @@ -50,16 +47,27 @@ main = hakyll $ do posts :: Compiler [Item String] posts = recentFirst =<< loadAll "log/*.org" +articles :: Compiler [Item String] +articles = loadAll "article/**" + +recentPosts :: Compiler [Item String] +recentPosts = (take 4) <$> posts + +recentArticles :: Compiler [Item String] +recentArticles = (take 4) <$> articles + indexCtx :: Context String indexCtx = - listField "posts" postCtx posts <> - constField "title" "Home" <> - defaultContext + listField "articles" defaultContext recentArticles + <> listField "rposts" defaultContext recentPosts + <> constField "essays" "Soon" + <> constField "title" "Home" + <> defaultContext archiveCtx :: Context String archiveCtx = - constField "title" "archive of log posts" <> - defaultContext + constField "title" "archive of log posts" + <> defaultContext postCtx :: Context String postCtx = @@ -67,9 +75,10 @@ postCtx = postForArchiveCtx :: Context String postForArchiveCtx = - listField "posts" dateForArchiveCtx posts <> - defaultContext + listField "posts" dateForArchiveCtx posts + <> defaultContext dateForArchiveCtx :: Context String dateForArchiveCtx = dateField "date" "%d %b %Y" <> defaultContext + -- cgit v1.3-2-g0d8e