Update hakyll-init example to new template system
This commit is contained in:
parent
569c6e035a
commit
fd917217ae
6 changed files with 20 additions and 25 deletions
|
@ -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>.
|
||||
|
|
|
@ -31,8 +31,9 @@ main = hakyll $ do
|
|||
create ["archive.html"] $ do
|
||||
route idRoute
|
||||
compile $ do
|
||||
posts <- recentFirst =<< loadAll "posts/*"
|
||||
let archiveCtx =
|
||||
field "posts" (\_ -> postList recentFirst) `mappend`
|
||||
listField "posts" postCtx (return posts) `mappend`
|
||||
constField "title" "Archives" `mappend`
|
||||
defaultContext
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
<ul>
|
||||
$posts$
|
||||
</ul>
|
||||
Here you can find all my previous posts:
|
||||
$partial("templates/post-list.html")$
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
<li>
|
||||
<a href="$url$">$title$</a> - $date$
|
||||
</li>
|
7
data/example/templates/post-list.html
Normal file
7
data/example/templates/post-list.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
<ul>
|
||||
$for(posts)$
|
||||
<li>
|
||||
<a href="$url$">$title$</a> - $date$
|
||||
</li>
|
||||
$endfor$
|
||||
</ul>
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue