on master help sign in
Update tutorial to new matching mechanism
commit19dc9f5f9fb8bda417e5b5dcc47b9cf83c541366 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 5 Apr 2011, 17:34 (16 years ago) parent8dd1f94
1 file changed+33−22
examples/hakyll/tutorial.markdown+33−22
examples/hakyll/tutorial.markdown+33−22
@@ -65,16 +65,18 @@ import Hakyll
6565
6666main :: IO ()
6767main = hakyll $ do
68− route "css/*" idRoute
69− compile "css/*" compressCssCompiler
70−
71− compile "templates/*" templateCompiler
72−
73− forM_ ["about.rst", "index.markdown", "code.lhs"] $ \page -> do
74− route page $ setExtension "html"
75− compile page $ pageCompiler
76− >>> applyTemplateCompiler "templates/default.html"
77− >>> relativizeUrlsCompiler
68+ match "css/*" $ do
69+ route idRoute
70+ compile compressCssCompiler
71+
72+ match "templates/*" $ compile templateCompiler
73+
74+ forM_ ["about.rst", "index.markdown", "code.lhs"] $ \page ->
75+ match page $ do
76+ route $ setExtension "html"
77+ compile $ pageCompiler
78+ >>> applyTemplateCompiler "templates/default.html"
79+ >>> relativizeUrlsCompiler
7880~~~~~
7981
8082This is enough code to create a small brochure site! You can find all code
@@ -111,12 +113,11 @@ main :: IO ()
111113main = hakyll $ do
112114~~~~~
113115
114−The `RulesM` monad is composed of a few functions. A first important one is
115−`route`: this creates a new rule for routing items. This rule is applied to all
116−items it matches -- and matching is done using the `"css/*"` [pattern].
117−`idRoute` simply means that an item will be routed to it's own filename. For
118−example, `css/screen.css` will be routed to `css/screen.css` -- not very
119−exciting.
116+The `RulesM` monad is composed of a few functions. Seldomly, you want to apply a
117+compiler to *all* resources. You want to apply a compiler to certain files
118+instead. That's why the `match` function exists. First, let's handle the CSS of
119+our file. We use a `"css/*"` [Pattern] to match all files in the `css/`
120+directory.
120121
121122Note that a [Pattern] matches an [Identifier], it doesn't match filenames.
122123
@@ -124,7 +125,16 @@ Note that a [Pattern] matches an [Identifier], it doesn't match filenames.
124125[Identifier]: /reference/Hakyll-Core-Identifier.html
125126
126127~~~~~{.haskell}
127−route "css/*" idRoute
128+match "css/*" $ do
129+~~~~~
130+
131+`route` creates a new rule for routing items. This rule is applied to all items
132+that are currently matched -- in this case, `"css/*"`. `idRoute` simply means
133+that an item will be routed to it's own filename. For example, `css/screen.css`
134+will be routed to `css/screen.css` -- not very exciting.
135+
136+~~~~~{.haskell}
137+route idRoute
128138~~~~~
129139
130140Apart from specifying where the items should go (using `route`), we also have to
@@ -135,12 +145,12 @@ good default compilers. The `compressCssCompiler` compiler will simply compress
135145the CSS found in the files.
136146
137147~~~~~{.haskell}
138−compile "css/*" compressCssCompiler
148+compile compressCssCompiler
139149~~~~~
140150
141151Next, we're going to render some pages. We're going to style the results a
142152little, so we're going to need a [Template]. We simply compile a template using
143−the `defaultTemplateRead` compiler, it's good enough in most cases.
153+the `templateCompiler` compiler, it's good enough in most cases.
144154
145155[Template]: /reference/Hakyll-Web-Template.html
146156
@@ -148,7 +158,7 @@ We don't use a route for these templates, after all, we don't want to route them
148158anywhere, we just want to use them to style our pages a little.
149159
150160~~~~~{.haskell}
151−compile "templates/*" templateCompiler
161+match "templates/*" $ compile templateCompiler
152162~~~~~
153163
154164We can conclude that some rules do not *directly* add an output page on our
@@ -164,13 +174,14 @@ manually).
164174
165175~~~~~{.haskell}
166176forM_ ["about.rst", "index.markdown", "code.lhs"] $ \page -> do
177+ match page $ do
167178~~~~~
168179
169180The pages all have different extensions. In our website, we only want to see
170181`.html` files. Hakyll provides a route to do just that:
171182
172183~~~~~{.haskell}
173−route page $ setExtension "html"
184+route setExtension "html"
174185~~~~~
175186
176187The [Rules] reference page has a complete listing of the API used.
@@ -189,7 +200,7 @@ reference page has some more readable information on this subject.
189200[Compiler]: /reference/Hakyll-Core-Compiler.html
190201
191202~~~~~{.haskell}
192−compile page $ pageCompiler
203+compile pageCompiler
193204 >>> applyTemplateCompiler "templates/default.html"
194205 >>> relativizeUrlsCompiler
195206~~~~~