on master help sign in
Better tutorial structure
commit8a8dade15ffc84f543fc3774f7a0a8fac4835bd2 authorJasper Van der Jeugt <m@jaspervdj.be> dateSun 16 Dec 2012, 00:21 (14 years ago) parent9b081b6
5 files changed+138−105
web/tutorials/02-basics.markdown+16−105 web/tutorials/03-rules-routes-compilers.markdown+117 web/tutorials/03-compilers.markdown → web/tutorials/04-compilers.markdown+5 web/tutorials/04-arrows.markdown → web/tutorials/05-arrows.markdown web/tutorials/05-guide.markdown → web/tutorials/06-guide.markdown
web/tutorials/02-basics.markdown+16−105
@@ -19,115 +19,26 @@ directories:
1919In general, it's only necessary to use `rebuild` when you made changes to your
2020`site.hs`, and not when you just made changes to the contents of your website.
2121
22−Basic rules
23−-----------
22+At this point, feel free to change some files, `./site build` and see what
23+happens!
2424
25−Let's take a look at the `site.hs` file.
25+Pages and metadata
26+------------------
2627
27−```haskell
28−main :: IO ()
29−main = hakyll $ do
30− ...
31−```
28+You might've noticed that the markdown pages all start with a block:
3229
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].
30+ ---
31+ title: Contact
32+ ---
3733
38−[Configuration]: /reference/Hakyll-Core-Configuration.html
34+ I live...
3935
40−Some actual rules look like this:
36+This is entirely optional, but useful for providing extra information
37+("metadata") about items. All items can have metadata: since it's not really
38+convenient to add such a header to an image, you can also do this using a
39+separate file.
4140
42−```haskell
43−match "images/*" $ do
44− route idRoute
45− compile copyFileCompiler
41+For a file called `images/foo.png`, you can add an `images/foo.png.metadata`
42+file with contents:
4643
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−Basic compilers
90−---------------
91−
92−More information can be found in the [Routes] module.
93−
94−[Routes]: /reference/Hakyll-Core-Routes.html
95−
96−The `compile` function determines how the content is produced for a certain
97−item. `compile` takes a value of the type `Compiler (Item a)`. Let's look at
98−some common examples:
99−
100−- `copyFileCompiler` is self-explanatory, the output is exactly the same as the
101− input;
102−- `getResourceBody` just gets you the content as a `String`, so you can perform
103− other manipulations afterwards;
104−- `compressCssCompiler` performs some simple build-in compression
105− transformations for CSS;
106−- `pandocCompiler` reads markdown, reStructuredText, or another input format and
107− renders it as HTML (if you want to pass specific options to pandoc, use
108− `pandocCompilerWith`).
109−
110−Compilers are very flexible: `Compiler` is a [Monad] and `Item` is a [Functor].
111−
112−[Monad]: http://learnyouahaskell.com/a-fistful-of-monads
113−[Functor]: http://learnyouahaskell.com/functors-applicative-functors-and-monoids
114−
115−A good example to illustrate the `Monad` instance for `Compiler` is
116−
117−```haskell
118−relativizeUrls :: Item String -> Compiler (Item String)
119−```
120−
121−This compiler traverses your HTML and changes absolute URLs (e.g.
122−`/posts/foo.markdown` into relative ones: `../posts/foo.markdown`). This is
123−extremely useful if you want to deploy your site in a subdirectory (e.g.
124−`jaspervdj.be/hakyll` instead of `jaspervdj.be`). Combining this with the
125−`pandocCompiler` gives us:
126−
127−```haskell
128−pandocCompiler >>= relativizeUrls :: Compiler (Item String)
129−```
130−
131−For a real website, you probably also want to use templates in order to give
132−your pages produced by pandoc a nice layout. We tackle this in the next
133−tutorial.
44+ title: An image of a cow
web/tutorials/03-rules-routes-compilers.markdownnew file+117
@@ -0,0 +1,117 @@
1+---
2+title: Rules, routes and compilers
3+author: Jasper Van der Jeugt
4+---
5+
6+Basic rules
7+-----------
8+
9+While changing the content is nice, you'll have time for that once your site is
10+configured. Configuration is done using the `site.hs` file: let's take a look at
11+it!
12+
13+```haskell
14+main :: IO ()
15+main = hakyll $ do
16+ ...
17+```
18+
19+Hakyll configurations are in the `Rules` monad. In order to run them, the
20+`hakyll` function is used, so your main function usually starts this way.
21+`hakyllWith` is also available, this function allows you specify a custom
22+[Configuration].
23+
24+[Configuration]: /reference/Hakyll-Core-Configuration.html
25+
26+Some actual rules look like this:
27+
28+```haskell
29+match "images/*" $ do
30+ route idRoute
31+ compile copyFileCompiler
32+
33+match "css/*" $ do
34+ route idRoute
35+ compile compressCssCompiler
36+
37+```
38+
39+This is a declarative DSL: the order in which you write the rules make little
40+difference: Hakyll will use dependency tracking to determine the correct order.
41+
42+We group the different rules using `match`. The first argument for `match` is a
43+[Pattern]. The `OverloadedStrings` extension allows us to just write `String`s
44+here, which are interpreted as globs --- all files in the `images/` directory,
45+and all files in the `css/` directory.
46+
47+[Pattern]: /reference/Hakyll-Core-Identifier-Pattern.html
48+
49+Basic routes
50+------------
51+
52+The `route` function is used for determining the output file. For example, you
53+probably want to write the processed contents of `contact.markdown` to
54+`_site/contact.html` and not `_site/contact.markdown`.
55+
56+`idRoute` is a commonly used and just keeps the filename. We use this for e.g.
57+the images and CSS files.
58+
59+`setExtension` is another common route which takes a single argument: the
60+extension of the resulting file. In order to route `contact.markdown` to
61+`_site/contact.html`, use:
62+
63+```haskell
64+route $ setExtension "html"
65+```
66+
67+`customRoute` is a more advanced higher-order function which allows for even
68+more customization. You want to route `contact.markdown` to
69+`_site/nwodkram.tcatnoc`? No problem, just use:
70+
71+```haskell
72+route $ customRoute $ reverse . toFilePath
73+```
74+
75+More information can be found in the [Routes] module.
76+
77+[Routes]: /reference/Hakyll-Core-Routes.html
78+
79+Basic compilers
80+---------------
81+
82+The `compile` function determines how the content is produced for a certain
83+item. `compile` takes a value of the type `Compiler (Item a)`. Let's look at
84+some common examples:
85+
86+- `copyFileCompiler` is self-explanatory, the output is exactly the same as the
87+ input;
88+- `compressCssCompiler` performs some simple build-in compression
89+ transformations for CSS;
90+- `pandocCompiler` reads markdown, reStructuredText, or another input format and
91+ renders it as HTML (if you want to pass specific options to pandoc, use
92+ `pandocCompilerWith`).
93+
94+Compilers are very flexible: `Compiler` is a [Monad] and `Item` is a [Functor].
95+
96+[Monad]: http://learnyouahaskell.com/a-fistful-of-monads
97+[Functor]: http://learnyouahaskell.com/functors-applicative-functors-and-monoids
98+
99+A good example to illustrate the `Monad` instance for `Compiler` is
100+
101+```haskell
102+relativizeUrls :: Item String -> Compiler (Item String)
103+```
104+
105+This compiler traverses your HTML and changes absolute URLs (e.g.
106+`/posts/foo.markdown` into relative ones: `../posts/foo.markdown`). This is
107+extremely useful if you want to deploy your site in a subdirectory (e.g.
108+`jaspervdj.be/hakyll` instead of `jaspervdj.be`). Combining this with the
109+`pandocCompiler` gives us:
110+
111+```haskell
112+pandocCompiler >>= relativizeUrls :: Compiler (Item String)
113+```
114+
115+For a real website, you probably also want to use templates in order to give
116+your pages produced by pandoc a nice layout. We tackle this in the next
117+tutorial.
web/tutorials/03-compilers.markdown → web/tutorials/04-compilers.markdownrenamed+5
@@ -31,3 +31,8 @@ Sometimes you just want the *contents* and not the `Item`:
3131```haskell
3232loadBody "posts/foo.markdown" :: Compiler String
3333```
34+
35+This is all useful if we want to use Hakyll's templating system.
36+
37+Basic templates
38+---------------
web/tutorials/04-arrows.markdown → web/tutorials/05-arrows.markdownrenamed

The content is the same.

web/tutorials/05-guide.markdown → web/tutorials/06-guide.markdownrenamed

The content is the same.