on master help sign in
Updated tutorials.
8ff7025Jasper Van der Jeugt
examples/hakyll/tutorial4.markdown+10−20
@@ -39,17 +39,17 @@ template to render this. This is where `templates/rss.xml` comes in:
39 <title>The SimpleBlog</title>
39 <title>The SimpleBlog</title>
40 <link>http://jaspervdj.be/</link>
40 <link>http://jaspervdj.be/</link>
41 <description>Simple blog in hakyll</description>
41 <description>Simple blog in hakyll</description>
42− $items
42+ $body
43 </channel>
43 </channel>
44</rss>
44</rss>
45~~~~~
45~~~~~
46
46
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`
48yet - I'm going to work from bottom to top here, it's easier to explain it
48yet - I'm going to work from bottom to top here, it's easier to explain it
49that way).
49that way).
50
50
51~~~~~{.haskell}
51~~~~~{.haskell}
52−renderChain ["templates/rss.xml"] rssPage
52+renderChain ["templates/rss.xml"] rss
53~~~~~
53~~~~~
54
54
55This, as you can see, is a regular render chain, once again. We need make a
55This, 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,
73~~~~~
73~~~~~
74
74
75Since we build on the previous example, we still have our `renderablePosts`
75Since 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:
77
77
78~~~~~{.haskell}
78~~~~~{.haskell}
79−let recentRSSItems = renderAndConcat ["templates/rssitem.xml"]
79+let rss = createListing "rss.xml" "templates/rssitem.xml"
80− (take 3 renderablePosts)
80+ (take 3 renderablePosts) []
81~~~~~
81~~~~~
82
82
83−We're using the `renderAndConcat` function again. Note that because of
83+Note that we give `rss.xml` as destination url, because that is where we want
84−hakyll/haskell laziness, this action isn't executed directly, and this helps
84+our `CustomPage`. We give a template to render every post with
85−dependency handling.
85+(`"templates/rssitem.xml"`) and no additional context (so we use the empty list
86−
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−~~~~~
97
87
98## Adding a link to the feed
88## Adding a link to the feed
99
89
examples/hakyll/tutorial5.markdown+20−24
@@ -108,24 +108,18 @@ code into a more general function:
108
108
109~~~~{.haskell}
109~~~~{.haskell}
110renderPostList url title posts = do
110renderPostList url title posts = do
111− let postItems = renderAndConcatWith
112− postManipulation
111+ let list = createListingWith postManipulation
113− "templates/postitem.html"
114− (map createPagePath posts)
115− customPage = createCustomPage
116− url
117− ("templates/postitem.html" : posts)
112+ url "templates/postitem.html"
118− [ ("title", Left title)
113+ posts [("title", title)]
119− , ("posts", Right postItems)
120− ]
121− renderChain ["posts.html", "templates/default.html"]
114+ renderChain ["posts.html", "templates/default.html"] list
122− customPage
123~~~~~
115~~~~~
124
116
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
125−Our "render all posts" action can now be written as:
119+posts" action can now be written as:
126
120
127~~~~~{.haskell}
121~~~~~{.haskell}
128−renderPostList "posts.html" "All posts" postPaths
122+renderPostList "posts.html" "All posts" renderablePosts
129~~~~~
123~~~~~
130
124
131## Tag links
125## Tag links
@@ -136,7 +130,7 @@ clickable. We can again solve this with a `ContextManipulation`. We have a
136function that produces an url for a given tag:
130function that produces an url for a given tag:
137
131
138~~~~~{.haskell}
132~~~~~{.haskell}
139−tagToURL tag = "/tags/" ++ removeSpaces tag ++ ".html"
133+tagToURL tag = "$root/tags/" ++ removeSpaces tag ++ ".html"
140~~~~~
134~~~~~
141
135
142`removeSpaces` is an auxiliary function from `Text.Hakyll.File`. Now, there is
136`removeSpaces` is an auxiliary function from `Text.Hakyll.File`. Now, there is
@@ -151,6 +145,8 @@ postManipulation = renderDate "date" "%B %e, %Y" "Unknown date"
151 . renderTagLinks tagToURL
145 . renderTagLinks tagToURL
152~~~~~
146~~~~~
153
147
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>, ...`.
154If we click a tag, we get a `404`. That's because we haven't generated the
150If we click a tag, we get a `404`. That's because we haven't generated the
155post lists for every tag.
151post lists for every tag.
156
152
@@ -159,7 +155,8 @@ post lists for every tag.
159Hakyll provides a function called `readTagMap`. Let's inspect it's type.
155Hakyll provides a function called `readTagMap`. Let's inspect it's type.
160
156
161~~~~~{.haskell}
157~~~~~{.haskell}
158+type TagMap = Map String [FilePath]
162−readTagMap String [FilePath] -> Hakyll Map String [FilePath]
159+readTagMap String [FilePath] -> Hakyll TagMap
163~~~~~
160~~~~~
164
161
165You give it a list of paths, and it creates a map that, for every tag, holds
162You 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
183generate a tag cloud. Let's have a look at the `renderTagCloud` function.
180generate a tag cloud. Let's have a look at the `renderTagCloud` function.
184
181
185~~~~~{.haskell}
182~~~~~{.haskell}
186−renderTagCloud :: M.Map String [FilePath]
183+renderTagCloud :: TagMap
187 -> (String -> String)
184 -> (String -> String)
188 -> Float
185 -> Float
189 -> Float
186 -> Float
@@ -197,13 +194,12 @@ tag cloud back. We can add this to our index:
197
194
198~~~~~{.haskell}
195~~~~~{.haskell}
199let tagCloud = renderTagCloud tagMap tagToURL 100 200
196let tagCloud = renderTagCloud tagMap tagToURL 100 200
200−...
197+ index = createListingWith postManipulation "index.html"
201−createCustomPage "index.html"
202− ("templates/postitem.html" : take 3 postPaths)
198+ "templates/postitem.html"
199+ (take 3 renderablePosts)
203− [ ("title", Left "Home")
200+ [ ("title", "Home")
204− , ("posts", Right recentPosts)
205− , ("tagcloud", Left tagCloud)
201+ , ("tagcloud", tagCloud)
206− ]
202+ ]
207~~~~~
203~~~~~
208
204
209## That's it
205## That's it
examples/tagblog/hakyll.hs+1−1
@@ -31,7 +31,7 @@ main = hakyll $ do
31
31
32 -- Render index, including recent posts.
32 -- Render index, including recent posts.
33 let tagCloud = renderTagCloud tagMap tagToURL 100 200
33 let tagCloud = renderTagCloud tagMap tagToURL 100 200
34− let index = createListingWith postManipulation "index.html"
34+ index = createListingWith postManipulation "index.html"
35 "templates/postitem.html"
35 "templates/postitem.html"
36 (take 3 renderablePosts)
36 (take 3 renderablePosts)
37 [ ("title", "Home")
37 [ ("title", "Home")