on master help sign in
Updated tutorials.
commit8ff702589fb5a1a2e600b204970084466de58a09 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 29 Jan 2010, 13:58 (17 years ago) parent7128cc9
3 files changed+31−45
examples/hakyll/tutorial4.markdown+10−20 examples/hakyll/tutorial5.markdown+20−24 examples/tagblog/hakyll.hs+1−1
examples/hakyll/tutorial4.markdown+10−20
@@ -39,17 +39,17 @@ template to render this. This is where `templates/rss.xml` comes in:
3939 <title>The SimpleBlog</title>
4040 <link>http://jaspervdj.be/</link>
4141 <description>Simple blog in hakyll</description>
42− $items
42+ $body
4343 </channel>
4444</rss>
4545~~~~~
4646
47−We thus render our feed with the following code (no, I didn't define `rssPage`
47+We thus render our feed with the following code (no, I didn't define `rss`
4848yet - I'm going to work from bottom to top here, it's easier to explain it
4949that way).
5050
5151~~~~~{.haskell}
52−renderChain ["templates/rss.xml"] rssPage
52+renderChain ["templates/rss.xml"] rss
5353~~~~~
5454
5555This, 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,
7373~~~~~
7474
7575Since we build on the previous example, we still have our `renderablePosts`
76−list. We'll be using it again:
76+list. We'll be using it again to create a listing:
7777
7878~~~~~{.haskell}
79−let recentRSSItems = renderAndConcat ["templates/rssitem.xml"]
80− (take 3 renderablePosts)
79+let rss = createListing "rss.xml" "templates/rssitem.xml"
80+ (take 3 renderablePosts) []
8181~~~~~
8282
83−We're using the `renderAndConcat` function again. Note that because of
84−hakyll/haskell laziness, this action isn't executed directly, and this helps
85−dependency handling.
86−
87−Now, the `rssPage` page. As you might remember, we use the `createCustomPage`
88−function to create a custom page. We first give the destination url, then a
89−list of dependencies, and then a list of `(key, value)` pairs.
90−
91−~~~~~{.haskell}
92−let rssPage = createCustomPage
93− "rss.xml"
94− ("templates/postitem.html" : take 3 postPaths)
95− [("items", Right recentRSSItems)]
96−~~~~~
83+Note that we give `rss.xml` as destination url, because that is where we want
84+our `CustomPage`. We give a template to render every post with
85+(`"templates/rssitem.xml"`) and no additional context (so we use the empty list
86+`[]`).
9787
9888## Adding a link to the feed
9989
examples/hakyll/tutorial5.markdown+20−24
@@ -108,24 +108,18 @@ code into a more general function:
108108
109109~~~~{.haskell}
110110renderPostList url title posts = do
111− let postItems = renderAndConcatWith
112− postManipulation
113− "templates/postitem.html"
114− (map createPagePath posts)
115− customPage = createCustomPage
116− url
117− ("templates/postitem.html" : posts)
118− [ ("title", Left title)
119− , ("posts", Right postItems)
120− ]
121− renderChain ["posts.html", "templates/default.html"]
122− customPage
111+ let list = createListingWith postManipulation
112+ url "templates/postitem.html"
113+ posts [("title", title)]
114+ renderChain ["posts.html", "templates/default.html"] list
123115~~~~~
124116
125−Our "render all posts" action can now be written as:
117+As you can see, `createListing` also has a `xxxWith` variant that lets you
118+specify a `ContextManipulation` to apply on every `Renderable`. Our "render all
119+posts" action can now be written as:
126120
127121~~~~~{.haskell}
128−renderPostList "posts.html" "All posts" postPaths
122+renderPostList "posts.html" "All posts" renderablePosts
129123~~~~~
130124
131125## Tag links
@@ -136,7 +130,7 @@ clickable. We can again solve this with a `ContextManipulation`. We have a
136130function that produces an url for a given tag:
137131
138132~~~~~{.haskell}
139−tagToURL tag = "/tags/" ++ removeSpaces tag ++ ".html"
133+tagToURL tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
140134~~~~~
141135
142136`removeSpaces` is an auxiliary function from `Text.Hakyll.File`. Now, there is
@@ -151,6 +145,8 @@ postManipulation = renderDate "date" "%B %e, %Y" "Unknown date"
151145 . renderTagLinks tagToURL
152146~~~~~
153147
148+So, the `renderTagLinks` function replaces the `$tags` value from
149+`epic fail, random` to `<a href="$root/tags/epic-fail.html">epic fail</a>, ...`.
154150If we click a tag, we get a `404`. That's because we haven't generated the
155151post lists for every tag.
156152
@@ -159,7 +155,8 @@ post lists for every tag.
159155Hakyll provides a function called `readTagMap`. Let's inspect it's type.
160156
161157~~~~~{.haskell}
162−readTagMap String [FilePath] -> Hakyll Map String [FilePath]
158+type TagMap = Map String [FilePath]
159+readTagMap String [FilePath] -> Hakyll TagMap
163160~~~~~
164161
165162You 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
183180generate a tag cloud. Let's have a look at the `renderTagCloud` function.
184181
185182~~~~~{.haskell}
186−renderTagCloud :: M.Map String [FilePath]
183+renderTagCloud :: TagMap
187184 -> (String -> String)
188185 -> Float
189186 -> Float
@@ -197,13 +194,12 @@ tag cloud back. We can add this to our index:
197194
198195~~~~~{.haskell}
199196let tagCloud = renderTagCloud tagMap tagToURL 100 200
200−...
201−createCustomPage "index.html"
202− ("templates/postitem.html" : take 3 postPaths)
203− [ ("title", Left "Home")
204− , ("posts", Right recentPosts)
205− , ("tagcloud", Left tagCloud)
206− ]
197+ index = createListingWith postManipulation "index.html"
198+ "templates/postitem.html"
199+ (take 3 renderablePosts)
200+ [ ("title", "Home")
201+ , ("tagcloud", tagCloud)
202+ ]
207203~~~~~
208204
209205## That's it
examples/tagblog/hakyll.hs+1−1
@@ -31,7 +31,7 @@ main = hakyll $ do
3131
3232 -- Render index, including recent posts.
3333 let tagCloud = renderTagCloud tagMap tagToURL 100 200
34− let index = createListingWith postManipulation "index.html"
34+ index = createListingWith postManipulation "index.html"
3535 "templates/postitem.html"
3636 (take 3 renderablePosts)
3737 [ ("title", "Home")