on master help sign in
Docs on basic rules and routes
commit3f42c9cd6f45bb306d622f3ffa175e2a8b0910e1 authorJasper Van der Jeugt <m@jaspervdj.be> dateFri 14 Dec 2012, 13:49 (14 years ago) parentadc8cf8
4 files changed+73−15
data/example/site.hs−8 src/Hakyll/Core/Configuration.hs+4−4 src/Hakyll/Core/Routes.hs+2−2 web/tutorials/02-basics.markdown+67−1
data/example/site.hs−8
@@ -18,17 +18,9 @@ main = hakyll $ do
1818
1919 match (fromList ["about.rst", "contact.markdown"]) $ do
2020 route $ setExtension "html"
21− compile $ do
22−
23− defaultTpl <- loadBody "templates/default.html"
24− pageCompiler
25− >>= applyTemplate defaultTpl defaultContext
26− >>= relativizeUrls
27− {-
2821 compile $ pageCompiler
2922 >>= loadAndApplyTemplate "templates/default.html" defaultContext
3023 >>= relativizeUrls
31− -}
3224
3325 match "posts/*" $ do
3426 route $ setExtension "html"
src/Hakyll/Core/Configuration.hs+4−4
@@ -28,7 +28,7 @@ data Configuration = Configuration
2828 providerDirectory :: FilePath
2929 , -- | Function to determine ignored files
3030 --
31− -- In 'defaultHakyllConfiguration', the following files are ignored:
31+ -- In 'defaultConfiguration', the following files are ignored:
3232 --
3333 -- * files starting with a @.@
3434 --
@@ -38,9 +38,9 @@ data Configuration = Configuration
3838 --
3939 -- * files ending with @.swp@
4040 --
41− -- Note that the files in @destinationDirectory@ and @storeDirectory@ will
41+ -- Note that the files in 'destinationDirectory' and 'storeDirectory' will
4242 -- also be ignored. Note that this is the configuration parameter, if you
43− -- want to use the test, you should use @shouldIgnoreFile@.
43+ -- want to use the test, you should use 'shouldIgnoreFile'.
4444 --
4545 ignoreFile :: FilePath -> Bool
4646 , -- | Here, you can plug in a system command to upload/deploy your site.
@@ -51,7 +51,7 @@ data Configuration = Configuration
5151 --
5252 -- You can execute this by using
5353 --
54− -- > ./hakyll deploy
54+ -- > ./site deploy
5555 --
5656 deployCommand :: String
5757 , -- | Use an in-memory cache for items. This is faster but uses more
src/Hakyll/Core/Routes.hs+2−2
@@ -138,8 +138,8 @@ gsubRoute pattern replacement = customRoute $
138138
139139
140140--------------------------------------------------------------------------------
141−-- | Compose routes so that @f `composeRoutes` g@ is more or less equivalent
142−-- with @f >>> g@.
141+-- | Compose routes so that @f \`composeRoutes\` g@ is more or less equivalent
142+-- with @g . f@.
143143--
144144-- Example:
145145--
web/tutorials/02-basics.markdown+67−1
@@ -22,7 +22,73 @@ In general, it's only necessary to use `rebuild` when you made changes to your
2222Basic rules
2323-----------
2424
25−TODO
25+Let's take a look at the `site.hs` file.
26+
27+```haskell
28+main :: IO ()
29+main = hakyll $ do
30+ ...
31+```
32+
33+Hakyll configurations are in the `Rules` monad. In order to run them, the
34+`hakyll` function is used, so your main function usually starts this way.
35+`hakyllWith` is also available, this function allows you specify a custom
36+[Configuration].
37+
38+[Configuration]: /reference/Hakyll-Core-Configuration.html
39+
40+Some actual rules look like this:
41+
42+```haskell
43+match "images/*" $ do
44+ route idRoute
45+ compile copyFileCompiler
46+
47+match "css/*" $ do
48+ route idRoute
49+ compile compressCssCompiler
50+
51+```
52+
53+This is a declarative DSL: the order in which you write the rules make little
54+difference: Hakyll will use dependency tracking to determine the correct order.
55+
56+We group the different rules using `match`. The first argument for `match` is a
57+[Pattern]. The `OverloadedStrings` extension allows us to just write `String`s
58+here, which are interpreted as globs --- all files in the `images/` directory,
59+and all files in the `css/` directory.
60+
61+[Pattern]: /reference/Hakyll-Core-Identifier-Pattern.html
62+
63+Basic routes
64+------------
65+
66+The `route` function is used for determining the output file. For example, you
67+probably want to write the processed contents of `contact.markdown` to
68+`_site/contact.html` and not `_site/contact.markdown`.
69+
70+`idRoute` is a commonly used and just keeps the filename. We use this for e.g.
71+the images and CSS files.
72+
73+`setExtension` is another common route which takes a single argument: the
74+extension of the resulting file. In order to route `contact.markdown` to
75+`_site/contact.html`, use:
76+
77+```haskell
78+route $ setExtension "html"
79+```
80+
81+`customRoute` is a more advanced higher-order function which allows for even
82+more customization. You want to route `contact.markdown` to
83+`_site/nwodkram.tcatnoc`? No problem, just use:
84+
85+```haskell
86+customRoute $ reverse . toFilePath
87+```
88+
89+More information can be found in the [Routes] module.
90+
91+[Routes]: /reference/Hakyll-Core-Routes.html
2692
2793## Images
2894