-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathhakyll.hs
86 lines (69 loc) · 2.67 KB
/
hakyll.hs
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (id)
import Control.Category (id)
import Control.Arrow ((>>>), (***), arr, (>>^))
import Control.Applicative
import Data.Monoid (mempty, mconcat)
import Hakyll
import Tikz
import Text.Pandoc
import System.IO.Unsafe
renderPandocThrough ::(Compiler (Page Pandoc) (Page Pandoc)) -> Compiler Resource (Page String)
renderPandocThrough p = readPageCompiler >>> addDefaultFields >>> arr applySelf
>>> pageReadPandoc >>> p >>> arr (fmap writePandoc)
catTransformer = cached "Commutative Diagrams" $ renderPandocThrough $ catInplace
catInplace :: Compiler (Page Pandoc) (Page Pandoc)
catInplace = timedCompiler "Commutative diagrams" $ unsafeCompiler $ \(Page md b) -> do
compiled <- bottomUpM doTikz $ b
return $ (Page md compiled)
-- Python tipy preprocessor
py_pre :: Compiler Resource String
py_pre = getResourceString >>> unixFilter "tipy" ["--preprocess"]
-- MathJax as Math backend
pandocOptions :: WriterOptions
pandocOptions = defaultHakyllWriterOptions
{ writerHTMLMathMethod = MathJax ""
}
main :: IO ()
main = hakyll $ do
match "images/*" $ do
route idRoute
compile copyFileCompiler
match "css/*" $ do
route idRoute
compile compressCssCompiler
match "files/*" $ do
route idRoute
compile copyFileCompiler
match "templates/*" $ compile templateCompiler
match "index.md" $ do
route $ setExtension "html"
compile $ pageCompiler
>>> applyTemplateCompiler "templates/default.html"
>>> relativizeUrlsCompiler
match "posts/*" $ do
route $ setExtension "html"
compile $ py_pre
>>> arr readPage
>>> addDefaultFields
>>> pageRenderPandocWith defaultHakyllParserState pandocOptions
>>> applyTemplateCompiler "templates/default.html"
>>> relativizeUrlsCompiler
match "pages/*" $ do
route $ setExtension "html"
compile $ pageCompiler
>>> applyTemplateCompiler "templates/default.html"
>>> relativizeUrlsCompiler
match "posts.html" $ route idRoute
create "posts.html" $ constA mempty
>>> arr (setField "title" "All posts")
>>> requireAllA "posts/*" addPostList
>>> applyTemplateCompiler "templates/list.html"
>>> applyTemplateCompiler "templates/default.html"
>>> relativizeUrlsCompiler
addPostList :: Compiler (Page String, [Page String]) (Page String)
addPostList = setFieldA "posts" $
arr chronological
>>> require "templates/post.html" (\p t -> map (applyTemplate t) p)
>>> arr mconcat
>>> arr pageBody