on master help sign in
Docs on basic rules and routes
3f42c9cJasper Van der Jeugt
data/example/site.hs−8
@@ -18,17 +18,9 @@ main = hakyll $ do
18
18
19 match (fromList ["about.rst", "contact.markdown"]) $ do
19 match (fromList ["about.rst", "contact.markdown"]) $ do
20 route $ setExtension "html"
20 route $ setExtension "html"
21− compile $ do
22−
23− defaultTpl <- loadBody "templates/default.html"
24− pageCompiler
25− >>= applyTemplate defaultTpl defaultContext
26− >>= relativizeUrls
27− {-
28 compile $ pageCompiler
21 compile $ pageCompiler
29 >>= loadAndApplyTemplate "templates/default.html" defaultContext
22 >>= loadAndApplyTemplate "templates/default.html" defaultContext
30 >>= relativizeUrls
23 >>= relativizeUrls
31− -}
32
24
33 match "posts/*" $ do
25 match "posts/*" $ do
34 route $ setExtension "html"
26 route $ setExtension "html"
src/Hakyll/Core/Configuration.hs+4−4
@@ -28,7 +28,7 @@ data Configuration = Configuration
28 providerDirectory :: FilePath
28 providerDirectory :: FilePath
29 , -- | Function to determine ignored files
29 , -- | Function to determine ignored files
30 --
30 --
31− -- In 'defaultHakyllConfiguration', the following files are ignored:
31+ -- In 'defaultConfiguration', the following files are ignored:
32 --
32 --
33 -- * files starting with a @.@
33 -- * files starting with a @.@
34 --
34 --
@@ -38,9 +38,9 @@ data Configuration = Configuration
38 --
38 --
39 -- * files ending with @.swp@
39 -- * files ending with @.swp@
40 --
40 --
41− -- Note that the files in @destinationDirectory@ and @storeDirectory@ will
41+ -- Note that the files in 'destinationDirectory' and 'storeDirectory' will
42 -- also be ignored. Note that this is the configuration parameter, if you
42 -- 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'.
44 --
44 --
45 ignoreFile :: FilePath -> Bool
45 ignoreFile :: FilePath -> Bool
46 , -- | Here, you can plug in a system command to upload/deploy your site.
46 , -- | Here, you can plug in a system command to upload/deploy your site.
@@ -51,7 +51,7 @@ data Configuration = Configuration
51 --
51 --
52 -- You can execute this by using
52 -- You can execute this by using
53 --
53 --
54− -- > ./hakyll deploy
54+ -- > ./site deploy
55 --
55 --
56 deployCommand :: String
56 deployCommand :: String
57 , -- | Use an in-memory cache for items. This is faster but uses more
57 , -- | 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 $
138
138
139
139
140--------------------------------------------------------------------------------
140--------------------------------------------------------------------------------
141−-- | Compose routes so that @f `composeRoutes` g@ is more or less equivalent
141+-- | Compose routes so that @f \`composeRoutes\` g@ is more or less equivalent
142−-- with @f >>> g@.
142+-- with @g . f@.
143--
143--
144-- Example:
144-- Example:
145--
145--
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
22Basic rules
22Basic rules
23-----------
23-----------
24
24
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
26
92
27## Images
93## Images
28
94