summaryrefslogtreecommitdiff
path: root/web/hakyll.hs
blob: 6dcb623dea245ca2aeea6122e86bc133a1618244 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{-# LANGUAGE OverloadedStrings #-}
import Hakyll
import Control.Monad (forM_)
import Control.Arrow ((>>>), arr)
import Data.Monoid (mempty)
import Text.Pandoc

main :: IO ()
main = hakyllWith config $ do
    match "css/*" $ do
        route   idRoute
        compile compressCssCompiler

    -- Static directories
    forM_ ["images/*", "examples/*", "reference/**"] $ \f -> match f $ do
        route   idRoute
        compile copyFileCompiler

    -- Pages
    forM_ pages $ \p -> match p $ do
        route   $ setExtension "html"
        compile $ pageCompiler
            >>> requireA "sidebar.markdown" (setFieldA "sidebar" $ arr pageBody)
            >>> applyTemplateCompiler "templates/default.html"
            >>> relativizeUrlsCompiler

    -- Tutorials
    match "tutorials/*" $ do
        route   $ setExtension "html"
        compile $ pageCompilerWith defaultHakyllParserState withToc
            >>> requireA "sidebar.markdown" (setFieldA "sidebar" $ arr pageBody)
            >>> applyTemplateCompiler "templates/tutorial.html"
            >>> applyTemplateCompiler "templates/default.html"
            >>> relativizeUrlsCompiler

    -- Tutorial list
    match "tutorials.html" $ route idRoute
    create "tutorials.html" $ constA mempty
        >>> arr (setField "title" "Tutorials")
        >>> setFieldPageList chronological
                "templates/tutorial-item.html" "tutorials" "tutorials/*"
        >>> requireA "sidebar.markdown" (setFieldA "sidebar" $ arr pageBody)
        >>> applyTemplateCompiler "templates/tutorials.html"
        >>> applyTemplateCompiler "templates/default.html"
        >>> relativizeUrlsCompiler

    -- Sidebar
    match "sidebar.markdown" $ compile pageCompiler

    -- Templates
    match "templates/*" $ compile templateCompiler
  where
    withToc = defaultHakyllWriterOptions
        { writerTableOfContents = True
        , writerTemplate = "$toc$\n$body$"
        , writerStandalone = True
        }

    pages = [ "about.markdown"
            , "changelog.markdown"
            , "examples.markdown"
            , "index.markdown"
            , "philosophy.markdown"
            , "reference.markdown"
            ]

config :: HakyllConfiguration
config = defaultHakyllConfiguration
    { deployCommand = "rsync --checksum -ave 'ssh -p 2222' \
                      \_site/* jaspervdj@jaspervdj.be:jaspervdj.be/hakyll"
    }