diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-12-14 13:49:51 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-12-14 13:49:51 +0100 |
commit | 3f42c9cd6f45bb306d622f3ffa175e2a8b0910e1 (patch) | |
tree | 41cef450bcf59af156b438b0530e7f8880a2440d /web/tutorials/02-basics.markdown | |
parent | adc8cf8528e7c9d95e2a8406a02e69cce858f088 (diff) | |
download | hakyll-3f42c9cd6f45bb306d622f3ffa175e2a8b0910e1.tar.gz |
Docs on basic rules and routes
Diffstat (limited to 'web/tutorials/02-basics.markdown')
-rw-r--r-- | web/tutorials/02-basics.markdown | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/web/tutorials/02-basics.markdown b/web/tutorials/02-basics.markdown index f29b549..f4d781b 100644 --- a/web/tutorials/02-basics.markdown +++ b/web/tutorials/02-basics.markdown @@ -22,7 +22,73 @@ In general, it's only necessary to use `rebuild` when you made changes to your Basic rules ----------- -TODO +Let's take a look at the `site.hs` file. + +```haskell +main :: IO () +main = hakyll $ do + ... +``` + +Hakyll configurations are in the `Rules` monad. In order to run them, the +`hakyll` function is used, so your main function usually starts this way. +`hakyllWith` is also available, this function allows you specify a custom +[Configuration]. + +[Configuration]: /reference/Hakyll-Core-Configuration.html + +Some actual rules look like this: + +```haskell +match "images/*" $ do + route idRoute + compile copyFileCompiler + +match "css/*" $ do + route idRoute + compile compressCssCompiler + +``` + +This is a declarative DSL: the order in which you write the rules make little +difference: Hakyll will use dependency tracking to determine the correct order. + +We group the different rules using `match`. The first argument for `match` is a +[Pattern]. The `OverloadedStrings` extension allows us to just write `String`s +here, which are interpreted as globs --- all files in the `images/` directory, +and all files in the `css/` directory. + +[Pattern]: /reference/Hakyll-Core-Identifier-Pattern.html + +Basic routes +------------ + +The `route` function is used for determining the output file. For example, you +probably want to write the processed contents of `contact.markdown` to +`_site/contact.html` and not `_site/contact.markdown`. + +`idRoute` is a commonly used and just keeps the filename. We use this for e.g. +the images and CSS files. + +`setExtension` is another common route which takes a single argument: the +extension of the resulting file. In order to route `contact.markdown` to +`_site/contact.html`, use: + +```haskell +route $ setExtension "html" +``` + +`customRoute` is a more advanced higher-order function which allows for even +more customization. You want to route `contact.markdown` to +`_site/nwodkram.tcatnoc`? No problem, just use: + +```haskell +customRoute $ reverse . toFilePath +``` + +More information can be found in the [Routes] module. + +[Routes]: /reference/Hakyll-Core-Routes.html ## Images |