From fd917217ae218d7369a84c0b0dcdd9cfa937ca2a Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Wed, 5 Jun 2013 14:10:07 +0200 Subject: Update hakyll-init example to new template system --- data/example/index.html | 5 +---- data/example/site.hs | 23 +++++++++-------------- data/example/templates/archive.html | 5 ++--- data/example/templates/post-item.html | 3 --- data/example/templates/post-list.html | 7 +++++++ 5 files changed, 19 insertions(+), 24 deletions(-) delete mode 100644 data/example/templates/post-item.html create mode 100644 data/example/templates/post-list.html (limited to 'data') diff --git a/data/example/index.html b/data/example/index.html index 950111c..16a42f9 100644 --- a/data/example/index.html +++ b/data/example/index.html @@ -11,9 +11,6 @@ title: Home

I've reproduced a list of recent posts here for your reading pleasure:

Posts

- - +$partial("templates/post-list.html")$

…or you can find more in the archives. 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 diff --git a/data/example/templates/archive.html b/data/example/templates/archive.html index bc732f9..b43eeb2 100644 --- a/data/example/templates/archive.html +++ b/data/example/templates/archive.html @@ -1,3 +1,2 @@ -

+Here you can find all my previous posts: +$partial("templates/post-list.html")$ diff --git a/data/example/templates/post-item.html b/data/example/templates/post-item.html deleted file mode 100644 index decbc33..0000000 --- a/data/example/templates/post-item.html +++ /dev/null @@ -1,3 +0,0 @@ -
  • - $title$ - $date$ -
  • diff --git a/data/example/templates/post-list.html b/data/example/templates/post-list.html new file mode 100644 index 0000000..71cf1b9 --- /dev/null +++ b/data/example/templates/post-list.html @@ -0,0 +1,7 @@ + -- cgit v1.2.3