diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-06-05 14:10:07 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-06-05 14:10:11 +0200 |
commit | fd917217ae218d7369a84c0b0dcdd9cfa937ca2a (patch) | |
tree | eda9e2ec83fa4f5835041e521246b1b9abf7d70a /data | |
parent | 569c6e035a10c2e3692b5cf72211ea2ad5526b01 (diff) | |
download | hakyll-fd917217ae218d7369a84c0b0dcdd9cfa937ca2a.tar.gz |
Update hakyll-init example to new template system
Diffstat (limited to 'data')
-rw-r--r-- | data/example/index.html | 5 | ||||
-rw-r--r-- | data/example/site.hs | 23 | ||||
-rw-r--r-- | data/example/templates/archive.html | 5 | ||||
-rw-r--r-- | data/example/templates/post-item.html | 3 | ||||
-rw-r--r-- | data/example/templates/post-list.html | 7 |
5 files changed, 19 insertions, 24 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> |