aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: 50a562dc6a718448b5b87a3c7d0709581f7d494a (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
{-# LANGUAGE OverloadedStrings #-}

import           Data.List        (sortBy)
import           Data.Monoid      (mappend)
import           Data.Ord         (comparing)
import           Hakyll
import           Hakyll.Core.Item (Item (itemIdentifier))
import           System.Process   (readProcess)
import qualified System.Process   as Process (rawSystem)

main :: IO ()
main = hakyllWith configuration $ do
  match "images/*" $ do
    route   idRoute
    compile copyFileCompiler

  match "design/**" $ do
    route $ customRoute $ const "main.css"
    compile $ do
      filePath <- getResourceFilePath
      unsafeCompiler (readProcess "runghc" [ filePath ] "")
        >>= makeItem

  match "js/src/**" $ do
    route $ customRoute $ const "main.js"
    compile $
      unsafeCompiler (readProcess "pulp" [ "--psc-package", "build", "--optimise", "--src-path", "js" ] "")
        >>= makeItem

  match "recettes/**" $ do
    route $ setExtension "html"
    compile $ pandocCompiler
      >>= loadAndApplyTemplate "templates/recipe.html" defaultContext
      >>= relativizeUrls

  match "index.html" $ do
    route idRoute
    let context =
          listField "mainDishes" defaultContext (loadAll "recettes/plats/*") `mappend`
          listField "lowCarbDesserts" defaultContext (loadAll "recettes/desserts/hypoglucidique/*") `mappend`
          listField "highCarbDesserts" defaultContext (loadAll "recettes/desserts/hyperglucidique/*") `mappend`
          listField "cleaningRecipes" defaultContext (loadAll "recettes/nettoyage/*") `mappend`
          defaultContext
    compile $
      getResourceBody
          >>= applyAsTemplate context
          >>= loadAndApplyTemplate "templates/index.html" context
          >>= relativizeUrls

  match "templates/*" $ compile templateBodyCompiler

configuration :: Configuration
configuration = defaultConfiguration
  { destinationDirectory = "public"
  , deploySite = const $
      Process.rawSystem "rsync" [ "-avzh", "public/", "joris@guyonvarch.me:/var/www/cooking.guyonvarch.me" ]
  }