summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-29 13:58:29 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-29 13:58:29 +0100
commit8ff702589fb5a1a2e600b204970084466de58a09 (patch)
treedc0a0b1852ed1f48152448d22eda32f16176ad04
parent7128cc9b5f77eb40bfb0b04d74ddfe2e10a171fe (diff)
downloadhakyll-8ff702589fb5a1a2e600b204970084466de58a09.tar.gz
Updated tutorials.
-rw-r--r--examples/hakyll/tutorial4.markdown30
-rw-r--r--examples/hakyll/tutorial5.markdown44
-rw-r--r--examples/tagblog/hakyll.hs2
3 files changed, 31 insertions, 45 deletions
diff --git a/examples/hakyll/tutorial4.markdown b/examples/hakyll/tutorial4.markdown
index a53e795..4065fd7 100644
--- a/examples/hakyll/tutorial4.markdown
+++ b/examples/hakyll/tutorial4.markdown
@@ -39,17 +39,17 @@ template to render this. This is where `templates/rss.xml` comes in:
<title>The SimpleBlog</title>
<link>http://jaspervdj.be/</link>
<description>Simple blog in hakyll</description>
- $items
+ $body
</channel>
</rss>
~~~~~
-We thus render our feed with the following code (no, I didn't define `rssPage`
+We thus render our feed with the following code (no, I didn't define `rss`
yet - I'm going to work from bottom to top here, it's easier to explain it
that way).
~~~~~{.haskell}
-renderChain ["templates/rss.xml"] rssPage
+renderChain ["templates/rss.xml"] rss
~~~~~
This, as you can see, is a regular render chain, once again. We need make a
@@ -73,27 +73,17 @@ We want to render every post using the following template,
~~~~~
Since we build on the previous example, we still have our `renderablePosts`
-list. We'll be using it again:
+list. We'll be using it again to create a listing:
~~~~~{.haskell}
-let recentRSSItems = renderAndConcat ["templates/rssitem.xml"]
- (take 3 renderablePosts)
+let rss = createListing "rss.xml" "templates/rssitem.xml"
+ (take 3 renderablePosts) []
~~~~~
-We're using the `renderAndConcat` function again. Note that because of
-hakyll/haskell laziness, this action isn't executed directly, and this helps
-dependency handling.
-
-Now, the `rssPage` page. As you might remember, we use the `createCustomPage`
-function to create a custom page. We first give the destination url, then a
-list of dependencies, and then a list of `(key, value)` pairs.
-
-~~~~~{.haskell}
-let rssPage = createCustomPage
- "rss.xml"
- ("templates/postitem.html" : take 3 postPaths)
- [("items", Right recentRSSItems)]
-~~~~~
+Note that we give `rss.xml` as destination url, because that is where we want
+our `CustomPage`. We give a template to render every post with
+(`"templates/rssitem.xml"`) and no additional context (so we use the empty list
+`[]`).
## Adding a link to the feed
diff --git a/examples/hakyll/tutorial5.markdown b/examples/hakyll/tutorial5.markdown
index 371d2ca..8ccb3bd 100644
--- a/examples/hakyll/tutorial5.markdown
+++ b/examples/hakyll/tutorial5.markdown
@@ -108,24 +108,18 @@ code into a more general function:
~~~~{.haskell}
renderPostList url title posts = do
- let postItems = renderAndConcatWith
- postManipulation
- "templates/postitem.html"
- (map createPagePath posts)
- customPage = createCustomPage
- url
- ("templates/postitem.html" : posts)
- [ ("title", Left title)
- , ("posts", Right postItems)
- ]
- renderChain ["posts.html", "templates/default.html"]
- customPage
+ let list = createListingWith postManipulation
+ url "templates/postitem.html"
+ posts [("title", title)]
+ renderChain ["posts.html", "templates/default.html"] list
~~~~~
-Our "render all posts" action can now be written as:
+As you can see, `createListing` also has a `xxxWith` variant that lets you
+specify a `ContextManipulation` to apply on every `Renderable`. Our "render all
+posts" action can now be written as:
~~~~~{.haskell}
-renderPostList "posts.html" "All posts" postPaths
+renderPostList "posts.html" "All posts" renderablePosts
~~~~~
## Tag links
@@ -136,7 +130,7 @@ clickable. We can again solve this with a `ContextManipulation`. We have a
function that produces an url for a given tag:
~~~~~{.haskell}
-tagToURL tag = "/tags/" ++ removeSpaces tag ++ ".html"
+tagToURL tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
~~~~~
`removeSpaces` is an auxiliary function from `Text.Hakyll.File`. Now, there is
@@ -151,6 +145,8 @@ postManipulation = renderDate "date" "%B %e, %Y" "Unknown date"
. renderTagLinks tagToURL
~~~~~
+So, the `renderTagLinks` function replaces the `$tags` value from
+`epic fail, random` to `<a href="$root/tags/epic-fail.html">epic fail</a>, ...`.
If we click a tag, we get a `404`. That's because we haven't generated the
post lists for every tag.
@@ -159,7 +155,8 @@ post lists for every tag.
Hakyll provides a function called `readTagMap`. Let's inspect it's type.
~~~~~{.haskell}
-readTagMap String [FilePath] -> Hakyll Map String [FilePath]
+type TagMap = Map String [FilePath]
+readTagMap String [FilePath] -> Hakyll TagMap
~~~~~
You give it a list of paths, and it creates a map that, for every tag, holds
@@ -183,7 +180,7 @@ A tag cloud is a commonly found thing on blogs. Hakyll also provides code to
generate a tag cloud. Let's have a look at the `renderTagCloud` function.
~~~~~{.haskell}
-renderTagCloud :: M.Map String [FilePath]
+renderTagCloud :: TagMap
-> (String -> String)
-> Float
-> Float
@@ -197,13 +194,12 @@ tag cloud back. We can add this to our index:
~~~~~{.haskell}
let tagCloud = renderTagCloud tagMap tagToURL 100 200
-...
-createCustomPage "index.html"
- ("templates/postitem.html" : take 3 postPaths)
- [ ("title", Left "Home")
- , ("posts", Right recentPosts)
- , ("tagcloud", Left tagCloud)
- ]
+ index = createListingWith postManipulation "index.html"
+ "templates/postitem.html"
+ (take 3 renderablePosts)
+ [ ("title", "Home")
+ , ("tagcloud", tagCloud)
+ ]
~~~~~
## That's it
diff --git a/examples/tagblog/hakyll.hs b/examples/tagblog/hakyll.hs
index de1d1a0..03dd488 100644
--- a/examples/tagblog/hakyll.hs
+++ b/examples/tagblog/hakyll.hs
@@ -31,7 +31,7 @@ main = hakyll $ do
-- Render index, including recent posts.
let tagCloud = renderTagCloud tagMap tagToURL 100 200
- let index = createListingWith postManipulation "index.html"
+ index = createListingWith postManipulation "index.html"
"templates/postitem.html"
(take 3 renderablePosts)
[ ("title", "Home")