@@ -0,0 +1,123 @@
2+title: Tutorial (Part III)
5+## Adding RSS to our simple blog
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).
11+An RSS feed looks like this:
14+<?xml version="1.0" ?>
17+ <title>The SimpleBlog</title>
18+ <link>http://example.com/</link>
19+ <description>Simple blog in hakyll</description>
21+ <title>Title goes here</title>
22+ <link>http://example.com/post.html</link>
24+ A description is optional.
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:
35+<?xml version="1.0" ?>
38+ <title>The SimpleBlog</title>
39+ <link>http://jaspervdj.be/</link>
40+ <description>Simple blog in hakyll</description>
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
51+renderChain ["templates/rss.xml"] rssPage
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).
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.
63+We want to render every post using the following template,
64+`templates/rssitem.xml`:
68+ <title>$title</title>
69+ <link>http://example.com/$url</link>
70+ <description>$title by $author</description>
74+Since we build on the previous example, we still have our `renderablePosts`
75+list. We'll be using it again:
78+let recentRSSItems = renderAndConcat "templates/rssitem.xml"
79+ (take 3 renderablePosts)
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
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.
91+let rssPage = createCustomPage
93+ ("templates/postitem.html" : take 3 postPaths)
94+ [("items", Right recentRSSItems)]
97+## Adding a link to the feed
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`:
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"
110+ href="http://example.com/rss.xml" />
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
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).