@@ -10,6 +10,18 @@ Inspired by [xmonad](http://xmonad.org), a small Haskell program is used as
1010configuration file. In this file, you give instructions on how the site should
1111be generated. In the rest of this document, we will examine a small example.
1212
13+This is our directory layout:
14+
15+ |-- _site
16+ |-- favicon.ico
17+ |-- hakyll.hs
18+ |-- images
19+ | `-- foo.png
20+ |-- templates
21+ | |-- default.html
22+ | `-- sample.html
23+ `-- text.markdown
24+
1325## Static files
1426
1527Static files can be rendered using the `static` command. This command ensures
@@ -110,4 +122,58 @@ function uses to determine the file destination.
110122
111123Sometimes, you want to create a `Page` from scratch, without reading from a
112124file. There are functions to do that for you, and I suggest you read the
113−documentation of `Text.Hakyll.Page`.
125+documentation of `Text.Hakyll.Page`. As a more advanced example, I will
126+explain the RSS system I wrote for my website.
127+
128+ |-- generate.hs
129+ |-- posts
130+ | `-- 2009-12-02-a-first-post.markdown
131+ `-- templates
132+ |-- rss.xml
133+ `-- rssitem.xml
134+
135+Our post contains some metadata:
136+
137+ ---
138+ title: A first post
139+ date: December 2, 2009
140+ ---
141+
142+ # A first post
143+
144+ A first post describing the technical setup of this blog, for that is
145+
146+The `templates/rssitem.xml` file is a template for rendering one post to an
147+rss item:
148+
149+ <item>
150+ <title>$title</title>
151+ <link>http://jaspervdj.be/$url</link>
152+ <description>New blogpost: $title</description>
153+ </item>
154+
155+Now a template for rendering the whole rss feed, `templates/rss.xml`:
156+
157+ <?xml version="1.0" ?>
158+ <rss version="2.0">
159+ <channel>
160+ <title>jaspervdj - a personal blog</title>
161+ <link>http://jaspervdj.be/</link>
162+ <description>Personal blog of jaspervdj</description>
163+ $items
164+ </channel>
165+ </rss>
166+
167+Alright, let's get coding.
168+
169+ -- Find all posts paths.
170+ postPaths <- liftM (L.reverse . L.sort) $ getRecursiveContents "posts"
171+ -- Read and render all posts with the rssitem.xml template
172+ -- Also, only render 5 posts.
173+ pages <- mapM readPage (take 5 postPaths)
174+ items <- mapM (renderPage "templates/rssitem.xml") pages
175+ -- Render the result
176+ renderAndWrite "templates/rss.xml" $ pageFromList [ ("items", concatPages items),
177+ ("url", "rss.xml") ]
178+
179+That's that. Now we have a nice rss feed.