summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/example/index.html5
-rw-r--r--data/example/site.hs23
-rw-r--r--data/example/templates/archive.html5
-rw-r--r--data/example/templates/post-item.html3
-rw-r--r--data/example/templates/post-list.html7
-rw-r--r--hakyll.cabal2
6 files changed, 20 insertions, 25 deletions
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
<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>.
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 @@
-<ul>
- $posts$
-</ul>
+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 @@
-<li>
- <a href="$url$">$title$</a> - $date$
-</li>
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 @@
+<ul>
+ $for(posts)$
+ <li>
+ <a href="$url$">$title$</a> - $date$
+ </li>
+ $endfor$
+</ul>
diff --git a/hakyll.cabal b/hakyll.cabal
index fdf72e6..633a414 100644
--- a/hakyll.cabal
+++ b/hakyll.cabal
@@ -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