/
site-test.hs
294 lines (240 loc) · 10.7 KB
/
site-test.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
-------------
{-# LANGUAGE OverloadedStrings #-}
import Data.Monoid (mappend)
import Hakyll
import qualified Data.Set as S
import qualified Data.Map as M
import Text.Pandoc.Options
-- Config
siteConfig = defaultConfiguration
{
deployCommand = "make cv.pdf; rsync -avz --exclude '.git' --delete _site/ nfsn:/home/public"
}
-- Main
main :: IO ()
main = hakyllWith siteConfig $ do
match "images/*" $ do
route idRoute
compile copyFileCompiler
match "js/*.js" $ do
route idRoute
compile copyFileCompiler
match (fromList ["cv.pdf", "favicon.ico", "robots.txt"]) $ do
route idRoute
compile copyFileCompiler
match "htaccess" $ do
route (constRoute ".htaccess")
compile copyFileCompiler
match "css/*.scss" $ do
route $ setExtension "css"
compile $ getResourceString >>=
withItemBody (unixFilter "sass" ["-s", "--scss"]) >>=
return .fmap compressCss
match (fromList ["teaching.markdown", "site.markdown", "index.markdown", "software.markdown", "404.markdown", "410.markdown", "pgp.markdown"]) $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
match "cv.markdown" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/cv.html" defaultContext
>>= relativizeUrls
match "research/pub/*" $ do
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
match "research/prog/*" $ do
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
match "research/dis/*" $ do
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" postCtx
>>= relativizeUrls
create ["research/index.html"] $ do
route idRoute
compile $ do
pubs <- recentFirst =<< loadAllSnapshots "research/pub/*" "content"
progs <- recentFirst =<< loadAllSnapshots "research/prog/*" "content"
dis <- recentFirst =<< loadAllSnapshots "research/dis/*" "content"
let archiveCtx =
listField "pubs" postCtx (return pubs) `mappend`
listField "progs" postCtx (return progs) `mappend`
listField "dis" postCtx (return dis) `mappend`
constField "title" "Research – David Sanson" `mappend`
constField "section" "research" `mappend`
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/research-page.html" archiveCtx
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
>>= relativizeUrls
match "texts/*.md" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/texts.html" defaultContext
>>= relativizeUrls
create ["texts/index.html"] $ do
route idRoute
compile $ do
texts <- loadAll "texts/*.md"
let textCtx =
listField "posts" defaultContext (return texts) `mappend`
constField "title" "Philosophy Texts" `mappend`
constField "section" "teaching" `mappend`
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/texts-page.html" textCtx
>>= loadAndApplyTemplate "templates/default.html" textCtx
>>= relativizeUrls
match "handouts/*.md" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/handouts.html" defaultContext
>>= relativizeUrls
create ["handouts/index.html"] $ do
route idRoute
compile $ do
handouts <- loadAll "handouts/*.md"
let textCtx =
listField "posts" defaultContext (return handouts) `mappend`
constField "title" "Philosophy Handouts" `mappend`
constField "section" "teaching" `mappend`
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/handouts-page.html" textCtx
>>= loadAndApplyTemplate "templates/default.html" textCtx
>>= relativizeUrls
match "logic/index.markdown" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/course-page.html" defaultContext
>>= relativizeUrls
match (fromList ["logic/syllabus.markdown", "logic/assignments.markdown"]) $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/logic.html" defaultContext
>>= relativizeUrls
match "logic/flashcards/*.txt" $ do
route idRoute
compile copyFileCompiler
match "logic/flashcards/htaccess" $ do
route (constRoute "logic/flashcards/.htaccess")
compile copyFileCompiler
match (fromList ["logic/flashcards/HEADER.html"]) $ do
route idRoute
compile copyFileCompiler
match "logic/supplements/*.markdown" $ do
route $ setExtension "html"
compile $ pandocMathCompiler
>>= loadAndApplyTemplate "templates/logic-supp.html" defaultContext
>>= relativizeUrls
match "logic/supplements/revised/*.markdown" $ do
route $ setExtension "html"
compile $ pandocMathCompiler
>>= loadAndApplyTemplate "templates/logic-supp.html" defaultContext
>>= relativizeUrls
-- create ["logic/supplements/index.html"] $ do
-- route idRoute
-- compile $ do
--
-- logic <- loadAll "logic/supplements/*.markdown"
-- let textCtx =
-- listField "posts" defaultContext (return logic) `mappend`
-- constField "title" "Logic Textbook Supplements" `mappend`
-- constField "section" "teaching" `mappend`
-- constField "author" "David Sanson" `mappend`
-- defaultContext
--
-- makeItem ""
-- >>= loadAndApplyTemplate "templates/logic-supplements.html" textCtx
-- >>= loadAndApplyTemplate "templates/logic.html" textCtx
-- >>= relativizeUrls
--
match "logic/assn/*.markdown" $ do
route $ setExtension "html"
compile $ pandocMathCompiler
>>= loadAndApplyTemplate "templates/logic.html" defaultContext
>>= relativizeUrls
create ["logic/assn/index.html"] $ do
route idRoute
compile $ do
logic <- loadAll "logic/assn/*.markdown"
let textCtx =
listField "posts" defaultContext (return logic) `mappend`
constField "title" "Assignments" `mappend`
constField "section" "teaching" `mappend`
constField "author" "David Sanson" `mappend`
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/logic-assn.html" textCtx
>>= loadAndApplyTemplate "templates/logic.html" textCtx
>>= relativizeUrls
match (fromList ["363s2015/syllabus.markdown", "363s2015/assignments.markdown"]) $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/363s2015.html" defaultContext
>>= relativizeUrls
match "363s2015/index.markdown" $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/course-page.html" defaultContext
>>= relativizeUrls
match "gizmos/*.markdown" $ do
route $ gsubRoute "posts" (const "") `composeRoutes` rmDateRoute
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/post.html" gizmoPostCtx
>>= saveSnapshot "content"
>>= loadAndApplyTemplate "templates/default.html" gizmoPostCtx
>>= relativizeUrls
create ["gizmos/index.html"] $ do
route idRoute
compile $ do
gizmos <- recentFirst =<< loadAllSnapshots "gizmos/*.markdown" "content"
let archiveCtx =
listField "gizmos" postCtx (return gizmos) `mappend`
constField "title" "Gizmos – David Sanson" `mappend`
constField "section" "gizmos" `mappend`
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/gizmos-page.html" archiveCtx
>>= loadAndApplyTemplate "templates/default.html" archiveCtx
>>= relativizeUrls
match "templates/*" $ compile templateCompiler
-------------
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 $ if "mathjax" `M.member` metadata
then "<script type=\"text/javascript\" src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>"
else ""
gizmoPostCtx :: Context String
gizmoPostCtx =
dateField "date" "%B %e, %Y" `mappend`
constField "section" "gizmos" `mappend`
defaultContext
-- Take out the post/YYYY-MM-DD part from the post URL
rmDateRoute =
gsubRoute "/[0-9]{4}-[0-9]{2}-[0-9]{2}-" (const "/")
`composeRoutes` setExtension "html"
pandocMathCompiler =
let mathExtensions = [Ext_tex_math_dollars, Ext_tex_math_double_backslash,
Ext_latex_macros]
defaultExtensions = writerExtensions defaultHakyllWriterOptions
newExtensions = foldr S.insert defaultExtensions mathExtensions
writerOptions = defaultHakyllWriterOptions {
writerExtensions = newExtensions,
writerHTMLMathMethod = MathJax ""
}
in pandocCompilerWith defaultHakyllReaderOptions writerOptions