@@ -0,0 +1,67 @@
2+title: Producing multiple versions of a single file
3+author: Jasper Van der Jeugt
9+Suppose that you want to make your writings available in raw markdown format, in
10+addition to the HTML available on your website. Is this possible using Hakyll?
12+In the [previous tutorial], we explained how you can use snapshots to store an
13+item while it's being processed. However, this does not allow you to route it to
16+[previous tutorial]: /tutorials/05-snapshots-feeds.html
18+Instead, we must use `version` in order to do this. The type signature of
19+`version` does not reveal much:
22+version :: String -> Rules () -> Rules ()
25+So let's look at an example:
29+ route $ setExtension "html"
30+ compile $ pandocCompiler
31+ >>= loadAndApplyTemplate "templates/post.html" postCtx
32+ >>= loadAndApplyTemplate "templates/default.html" postCtx
35+match "posts/*" $ version "raw" $ do
37+ compile getResourceBody
40+Here, you can see how we produce two versions of each item in `posts/*`: one
41+`"raw"` version, and the default version.
43+Attention: patterns and versions
44+--------------------------------
46+However, there is one important thing to note: suppose you use `Pattern`s for a
47+function such as `loadAll`, e.g. to create an index page with all blogposts.
50+loadAll "posts/*" :: Compiler [Item String]
53+is valid code, but **probably not** what you want to do: this will select all
54+`posts/*` items, meaning, both your HTML posts, and the raw versions. In order
55+to fix this, use any of the following:
58+loadAll (noVersion "posts/*") :: Compiler [Item String]
61+for the default versions, i.e. the HTML pages, and:
64+loadAll ("posts/*" `withVersion` "raw") :: Compiler [Item String]