on master help sign in
Add a clay tutorial
commitf2905021ec094ee794017586581c175ee98e7bb2 authorJasper Van der Jeugt <m@jaspervdj.be> dateSun 13 Jan 2013, 12:36 (14 years ago) parentd129cdc
3 files changed+43−1
web/site.hs+5−1 web/tutorials/guide.markdown → web/tutorials/a-guide-to-the-hakyll-module-zoo.markdown web/tutorials/using-clay-with-hakyll.markdown+38
web/site.hs+5−1
@@ -3,6 +3,7 @@
33import Control.Applicative ((<$>))
44import Control.Arrow (second)
55import Control.Monad (forM_)
6+import Data.Char (isDigit)
67import Data.List (isPrefixOf, partition)
78import Data.Monoid (mappend)
89import Hakyll
@@ -111,4 +112,7 @@ hackage url
111112--------------------------------------------------------------------------------
112113-- | Partition tutorials into tutorial series & other articles
113114partitionTutorials :: [Item a] -> ([Item a], [Item a])
114−partitionTutorials = partition $ matches (fromRegex "\\d*-.*") . itemIdentifier
115+partitionTutorials = partition $ \i ->
116+ case splitPath (toFilePath $ itemIdentifier i) of
117+ [_, (x : _)] -> isDigit x
118+ _ -> False
web/tutorials/guide.markdown → web/tutorials/a-guide-to-the-hakyll-module-zoo.markdownrenamed

The content is the same.

web/tutorials/using-clay-with-hakyll.markdownnew file+38
@@ -0,0 +1,38 @@
1+---
2+title: Using Clay with Hakyll
3+author: Jasper Van der Jeugt
4+---
5+
6+[Clay](http://sebastiaanvisser.github.com/clay/) is a nice CSS preprocesser
7+written in Haskell. There are multiple options to use this together with Hakyll,
8+but in this short tutorial I focus on what I think is the best way.
9+
10+This method requires every Clay file to have a `main` function which just prints
11+the CSS. This would be an example of such a file:
12+
13+``` haskell
14+{-# LANGUAGE OverloadedStrings #-}
15+import Clay
16+import qualified Data.Text.Lazy.IO as T
17+
18+test :: Css
19+test = ...
20+
21+main :: IO ()
22+main = T.putStr $ render test
23+```
24+
25+Let's assume such a file is called `css/foo.hs`. In our compiled site, we want
26+to map this to `css/foo.css`. Hence, the route is a simple `setExtension`. For
27+compilation, we simply pass the Clay file through `runghc` with no options.
28+
29+```haskell
30+match "css/*.hs" $ do
31+ route $ setExtension "css"
32+ compile $ getResourceString >>= withItemBody (unixFilter "runghc" [])
33+```
34+
35+The major advantage of using this method (as opposed to importing the Clay files
36+in `site.hs`) is that now Hakyll will only recompile the Clay files when
37+necessary, and you don't have to manually recompile your `site.hs` each time you
38+want to tweak your CSS a little.