diff options
Diffstat (limited to 'data/example/site.hs')
-rw-r--r-- | data/example/site.hs | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/data/example/site.hs b/data/example/site.hs index 9e103bf..be041f8 100644 --- a/data/example/site.hs +++ b/data/example/site.hs @@ -31,9 +31,10 @@ main = hakyll $ do create ["archive.html"] $ do route idRoute compile $ do + posts <- recentFirst =<< loadAll "posts/*" let archiveCtx = - field "posts" (\_ -> postList recentFirst) `mappend` - constField "title" "Archives" `mappend` + listField "posts" postCtx (return posts) `mappend` + constField "title" "Archives" `mappend` defaultContext makeItem "" @@ -45,12 +46,15 @@ main = hakyll $ do match "index.html" $ do route idRoute compile $ do - let indexCtx = field "posts" $ \_ -> - postList $ fmap (take 3) . recentFirst + posts <- recentFirst =<< loadAll "posts/*" + let indexCtx = + listField "posts" postCtx (return posts) `mappend` + constField "title" "Home" `mappend` + defaultContext getResourceBody >>= applyAsTemplate indexCtx - >>= loadAndApplyTemplate "templates/default.html" postCtx + >>= loadAndApplyTemplate "templates/default.html" indexCtx >>= relativizeUrls match "templates/*" $ compile templateCompiler @@ -61,12 +65,3 @@ postCtx :: Context String postCtx = dateField "date" "%B %e, %Y" `mappend` defaultContext - - --------------------------------------------------------------------------------- -postList :: ([Item String] -> Compiler [Item String]) -> Compiler String -postList sortFilter = do - posts <- sortFilter =<< loadAll "posts/*" - itemTpl <- loadBody "templates/post-item.html" - list <- applyTemplateList itemTpl postCtx posts - return list |