Newer
Older
{-# LANGUAGE OverloadedStrings #-}
--------------------------------------------------------------------
-- |
-- Copyright : (c) Stephen Diehl 2013
-- License : MIT
-- Maintainer: stephen.m.diehl@gmail.com
-- Stability : experimental
-- Portability: non-portable
--
--------------------------------------------------------------------
module Main where
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Hakyll
import Text.Pandoc
import qualified Data.Map as M
import Data.Maybe (isJust)
import Text.Pandoc.Highlighting
import Hakyll.Images ( loadImage
, scaleImageCompiler
)
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
--------------------------------------------------------------------
-- Contexts
--------------------------------------------------------------------
postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y"
`mappend` mathCtx
`mappend` defaultContext
mathCtx :: Context String
mathCtx = field "mathjax" $ \item -> do
metadata <- getMetadata $ itemIdentifier item
return ""
return $ if isJust $ lookupString "mathjax" metadata
then "<script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML\"></script>"
else ""
archiveCtx posts =
listField "posts" postCtx (return posts)
`mappend` constField "title" "Archives"
`mappend` defaultContext
indexCtx posts =
listField "posts" postCtx (return posts)
`mappend` constField "title" "Home"
`mappend` defaultContext
--------------------------------------------------------------------
-- Rules
--------------------------------------------------------------------
static :: Rules ()
static = do
match "fonts/*" $ do
route idRoute
compile $ copyFileCompiler
match "img/*" $ do
route idRoute
compile $ copyFileCompiler
match "css/*" $ do
route idRoute
compile compressCssCompiler
match "js/*" $ do
route idRoute
compile $ copyFileCompiler
resize :: Rules ()
resize = do
route idRoute
compile $ loadImage
>>= scaleImageCompiler 140 140
pages :: Rules ()
pages = do
match "pages/*" $ do
route $ setExtension "html"
compile $ getResourceBody
>>= loadAndApplyTemplate "templates/page.html" postCtx
>>= relativizeUrls
posts :: Rules ()
posts = do
match "posts/*" $ do
route $ setExtension "html"
-- compile $ myPandocCompiler
compile $ bibtexCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= relativizeUrls
archive :: Rules ()
archive = do
create ["archive.html"] $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
makeItem ""
>>= loadAndApplyTemplate "templates/archive.html" (archiveCtx posts)
>>= relativizeUrls
cours :: Rules ()
cours = do
match "cours/*" $ do
route $ setExtension "html"
-- compile $ myPandocCompiler
compile $ bibtexCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= relativizeUrls
conc :: Rules ()
conc = do
create ["prog_conc.html"] $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "cours/*"
makeItem ""
>>= loadAndApplyTemplate "templates/archive.html" (archiveCtx posts)
>>= relativizeUrls
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
index :: Rules ()
index = do
match "index.html" $ do
route idRoute
compile $ do
posts <- recentFirst =<< loadAll "posts/*"
getResourceBody
>>= applyAsTemplate (indexCtx posts)
>>= relativizeUrls
templates :: Rules ()
templates = match "templates/*" $ compile templateCompiler
--------------------------------------------------------------------
-- Configuration
--------------------------------------------------------------------
myPandocCompiler :: Compiler (Item String)
myPandocCompiler = pandocCompilerWith defaultHakyllReaderOptions pandocOptions
pandocOptions :: WriterOptions
pandocOptions = defaultHakyllWriterOptions
{
writerExtensions = defaultPandocExtensions
, writerHTMLMathMethod = MathJax ""
}
-- Pandoc extensions used by the myPandocCompiler
defaultPandocExtensions :: Extensions
defaultPandocExtensions =
let extensions = [
-- Pandoc Extensions: http://pandoc.org/MANUAL.html#extensions
-- Math extensions
Ext_tex_math_dollars
, Ext_tex_math_double_backslash
, Ext_latex_macros
-- Code extensions
, Ext_fenced_code_blocks
, Ext_backtick_code_blocks
, Ext_fenced_code_attributes
, Ext_inline_code_attributes -- Inline code attributes (e.g. `<$>`{.haskell})
-- Markdown extensions
, Ext_implicit_header_references -- We also allow implicit header references (instead of inserting <a> tags)
, Ext_definition_lists -- Definition lists based on PHP Markdown
, Ext_yaml_metadata_block -- Allow metadata to be speficied by YAML syntax
, Ext_superscript -- Superscripts (2^10^ is 1024)
, Ext_subscript -- Subscripts (H~2~O is water)
, Ext_footnotes -- Footnotes ([^1]: Here is a footnote)
]
defaultExtensions = writerExtensions defaultHakyllWriterOptions
in foldr enableExtension defaultExtensions extensions
bibtexCompiler :: Compiler (Item String)
bibtexCompiler = do
getResourceBody
>>= withItemBody (unixFilter "pandoc" ["-F"
, "pandoc-numbering"
, "-F"
, "pandoc-crossref"
, "-t"
, "markdown"
])
>>= readPandocWith defaultHakyllReaderOptions
>>= return . writePandocWith pandocOptions
cfg :: Configuration
cfg = defaultConfiguration
main :: IO ()
main = hakyllWith cfg $ do
pages
posts