@@ -0,0 +1,123 @@
1+---
2+title: Tutorial (Part III)
3+---
4+
5+## Adding RSS to our simple blog
6+
7+In this tutorial, we're going to add an RSS feed to the blog we wrote in
8+[the previous tutorial](tutorial2.html). Here is a
9+[zip file containing the source](examples/rssblog.zip).
10+
11+An RSS feed looks like this:
12+
13+~~~~~{.xml}
14+<?xml version="1.0" ?>
15+<rss version="2.0">
16+ <channel>
17+ <title>The SimpleBlog</title>
18+ <link>http://example.com/</link>
19+ <description>Simple blog in hakyll</description>
20+ <item>
21+ <title>Title goes here</title>
22+ <link>http://example.com/post.html</link>
23+ <description>
24+ A description is optional.
25+ </description>
26+ </item>
27+ </channel>
28+</rss>
29+~~~~~
30+
31+Note that, obviously, there can be more than one item. We're going to use a
32+template to render this. This is where `templates/rss.xml` comes in:
33+
34+~~~~~{.xml}
35+<?xml version="1.0" ?>
36+<rss version="2.0">
37+ <channel>
38+ <title>The SimpleBlog</title>
39+ <link>http://jaspervdj.be/</link>
40+ <description>Simple blog in hakyll</description>
41+ $items
42+ </channel>
43+</rss>
44+~~~~~
45+
46+We thus render our feed with the following code (no, I didn't define `rssPage`
47+yet - I'm going to work from bottom to top here, it's easier to explain it
48+that way).
49+
50+~~~~~{.haskell}
51+renderChain ["templates/rss.xml"] rssPage
52+~~~~~
53+
54+This, as you can see, is a regular render chain, once again. We need make a
55+`Renderable` that "fills in" the `$items` identifier. We're going to do this
56+using a [custom page](tutorial2.html#custom-pages).
57+
58+## Custom pages again
59+
60+Note that we do not have to include all posts in the rss feed - only a few
61+recent ones. We'll settle on the latest three here.
62+
63+We want to render every post using the following template,
64+`templates/rssitem.xml`:
65+
66+~~~~~{.haskell}
67+<item>
68+ <title>$title</title>
69+ <link>http://example.com/$url</link>
70+ <description>$title by $author</description>
71+</item>
72+~~~~~
73+
74+Since we build on the previous example, we still have our `renderablePosts`
75+list. We'll be using it again:
76+
77+~~~~~{.haskell}
78+let recentRSSItems = renderAndConcat "templates/rssitem.xml"
79+ (take 3 renderablePosts)
80+~~~~~
81+
82+We're using the `renderAndConcat` function again. Note that because of
83+hakyll/haskell laziness, this action isn't executed directly, and this helps
84+dependency handling.
85+
86+Now, the `rssPage` page. As you might remember, we use the `createCustomPage`
87+function to create a custom page. We first give the destination url, then a
88+list of dependencies, and then a list of `(key, value)` pairs.
89+
90+~~~~~{.haskell}
91+let rssPage = createCustomPage
92+ "rss.xml"
93+ ("templates/postitem.html" : take 3 postPaths)
94+ [("items", Right recentRSSItems)]
95+~~~~~
96+
97+## Adding a link to the feed
98+
99+According to the w3 organization,
100+[you should add \<link\> tags](http://www.w3.org/QA/Tips/use-links) to your
101+documents, so we'll do this. In `templates/default.html`:
102+
103+~~~~~~{.html}
104+<head>
105+ <title>SimpleBlog - $title</title>
106+ <link rel="stylesheet" type="text/css" href="/css/default.css" />
107+ <link rel="alternate"
108+ type="application/rss+xml"
109+ title="SimpleBlog"
110+ href="http://example.com/rss.xml" />
111+</head>
112+~~~~~~
113+
114+This makes most browsers see the rss feed, and show it in the address bar.
115+If you want, you can also add a pretty button to your blog linking to
116+`rss.xml`.
117+
118+## That's it!
119+
120+Yep, that's it. Feel free to play with the source code in
121+[the zip file](examples/rssblog.zip) and extend the blog further. As always,
122+all questions are welcome on the
123+[google discussion group](http://groups.google.com/group/hakyll).