Update hakyll-init example to new template system

This commit is contained in:
Jasper Van der Jeugt 2013-06-05 14:10:07 +02:00
parent 569c6e035a
commit fd917217ae
6 changed files with 20 additions and 25 deletions

View file

@ -11,9 +11,6 @@ title: Home
<p>I've reproduced a list of recent posts here for your reading pleasure:</p>
<h2>Posts</h2>
<ul>
$posts$
</ul>
$partial("templates/post-list.html")$
<p>…or you can find more in the <a href="/archive.html">archives</a>.

View file

@ -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

View file

@ -1,3 +1,2 @@
<ul>
$posts$
</ul>
Here you can find all my previous posts:
$partial("templates/post-list.html")$

View file

@ -1,3 +0,0 @@
<li>
<a href="$url$">$title$</a> - $date$
</li>

View file

@ -0,0 +1,7 @@
<ul>
$for(posts)$
<li>
<a href="$url$">$title$</a> - $date$
</li>
$endfor$
</ul>

View file

@ -48,7 +48,7 @@ Data-files:
example/posts/2012-08-12-spqr.markdown
example/site.hs
example/images/haskell-logo.png
example/templates/post-item.html
example/templates/post-list.html
example/templates/default.html
example/templates/archive.html
example/templates/post.html