-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsite.hs
More file actions
280 lines (259 loc) · 8.75 KB
/
site.hs
File metadata and controls
280 lines (259 loc) · 8.75 KB
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
{-# LANGUAGE OverloadedStrings #-}
{-
- Copyright (C) 2013-2015 plaimi <www@plaimi.net>
-
- Copying and distribution of this file, with or without modification,
- are permitted in any medium without royalty provided the copyright
- notice and this notice are preserved. This file is offered as-is,
- without any warranty.
-}
import Control.Monad
(
filterM,
)
import Data.Char
(
toUpper,
)
import Data.Monoid
(
(<>),
)
import Hakyll.Core.Configuration
(
Configuration,
defaultConfiguration,
deployCommand,
)
import Hakyll.Core.Compiler
(
getResourceBody,
loadAll,
makeItem,
)
import Hakyll.Core.File
(
copyFileCompiler,
)
import Hakyll.Core.Identifier
(
fromFilePath,
)
import Hakyll.Core.Identifier.Pattern
(
Pattern,
fromList,
)
import Hakyll.Core.Item
(
Item,
itemIdentifier,
)
import Hakyll.Core.Metadata
(
MonadMetadata,
getMetadataField,
)
import Hakyll.Core.Routes
(
idRoute,
setExtension,
)
import Hakyll.Core.Rules
(
Rules,
compile,
create,
match,
route,
)
import Hakyll.Main
(
hakyllWith,
)
import Hakyll.Web.CompressCss
(
compressCssCompiler,
)
import Hakyll.Web.Html.RelativizeUrls
(
relativizeUrls,
)
import Hakyll.Web.Pandoc
(
pandocCompiler,
)
import Hakyll.Web.Template
(
applyAsTemplate,
loadAndApplyTemplate,
templateCompiler,
)
import Hakyll.Web.Template.Context
(
constField,
dateField,
defaultContext,
listField,
)
import Hakyll.Web.Template.List
(
recentFirst,
)
import Config
(
synchCommand,
synchTarget,
)
main :: IO ()
main = hakyllWith configuration $ do
-- Templates
match "templates/*" $ compile templateCompiler
-- CSS
match "css/*" $ do
route idRoute
compile compressCssCompiler
-- Pure file copy.
match (fromList ["~alexander/contact.txt"
,"~olle/contact.txt"
,"~emil/contact.txt"
]) copyFiles
-- Pure file copy with globs.
match "papers/*.pdf" copyFiles
match "images/*" copyFiles
match "presentations/*pdf" copyFiles
match (fromList ["about.markdown"
,"contact.markdown"
,"swag.markdown"
,"~alexander/haskell.markdown"
,"~alexander/index.markdown"
,"~olle/index.markdown"
,"~emil/index.markdown"]) $ do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
-- Markdown to HTML with template applied.
match "projects/*.markdown" $ mdToHtml "project"
match "news/*.markdown" $ mdToHtml "news"
match "works/*.markdown" $ mdToHtml "work"
match "games/*.markdown" $ mdToHtml "game"
match "papers/*.markdown" $ mdToHtml "paper"
match "presentations/*.markdown" $ mdToHtml "presentation"
match "other/*.markdown" $ mdToHtml "other"
-- Markdown to more category HTML sites. Category sites list all entries in
-- that specific category.
create ["works.html"] $ toCategoryHtml "works/*.markdown" "works" "work"
create ["games.html"] $ toCategoryHtml "games/*.markdown" "games" "game"
create ["other.html"] $ toCategoryHtml "other/*.markdown" "other" "other"
-- Markdown to archive HTML sites. Archives are like category sites but
-- date-sorted.
create ["news.html"] $ toArchiveHtml "news/*.markdown"
"news" "news"
create ["papers.html"] $ toArchiveHtml "papers/*.markdown"
"papers" "paper"
create ["presentations.html"] $ toArchiveHtml "presentations/*.markdown"
"presentations" "presentation"
-- index.html. It's messy. Sorry.
match "index.html" $ do
route idRoute
compile $ do
news <- recentFirst =<< loadAll "news/*.markdown"
games <- loadAll "games/*.markdown"
works <- loadAll "works/*.markdown"
papers <- recentFirst =<< loadAll "papers/*.markdown"
pres <- recentFirst =<< loadAll "presentations/*.markdown"
other <- loadAll "other/*.markdown"
let newsCtx = dateField "date" "%B %e, %Y"
<> defaultContext
let gameCtx = listField "games" defaultContext (return games)
<> defaultContext
let workCtx = listField "works" defaultContext (return works)
<> defaultContext
let paperCtx = dateField "date" "%B %e, %Y"
<> listField "papers" defaultContext (return papers)
<> defaultContext
let presCtx = dateField "date" "%B %e, %Y"
<> listField "presentations" defaultContext (return pres)
<> defaultContext
let otherCtx = listField "other" defaultContext (return other)
<> defaultContext
let indexCtx = listField "news" newsCtx (return news)
<> listField "works" workCtx (return works)
<> listField "games" gameCtx (return games)
<> listField "papers" paperCtx (return papers)
<> listField "presentations" presCtx (return pres)
<> listField "other" otherCtx (return other)
<> defaultContext
getResourceBody
>>= applyAsTemplate indexCtx
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls
match "mailing.html" $ do
route idRoute
compile $ getResourceBody
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
-- projects.html: list of all projects.
create ["projects.html"] $ do
route idRoute
compile $ do
games <- loadAll "games/*.markdown"
works <- loadAll "works/*.markdown"
papers <- recentFirst =<< loadAll "papers/*.markdown"
pres <- recentFirst =<< loadAll "presentations/*.markdown"
other <- loadAll "other/*.markdown"
let ctx = constField "title" "Projects"
<> listField "games" defaultContext (return games)
<> listField "works" defaultContext (return works)
<> listField "papers" defaultContext (return papers)
<> listField "presentations" defaultContext (return pres)
<> listField "other" defaultContext (return other)
<> defaultContext
makeItem "" >>= loadAndApplyTemplate "templates/project-list.html" ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
toArchiveHtml :: Pattern -> String -> String -> Rules ()
toArchiveHtml p f t = do
route idRoute
compile $ do
u <- recentFirst =<< loadAll p
let ctx = dateField "date" "%B %e, %Y" <> defaultContext
let actx = listField f ctx (return u)
<> constField "title" (toUpper (head f) : tail f)
<> defaultContext
makeItem "" >>= loadAndApplyTemplate (fromFilePath $ "templates/"
++ t
++ "-list.html") actx
>>= loadAndApplyTemplate "templates/default.html" actx
>>= relativizeUrls
toCategoryHtml :: Pattern -> String -> String -> Rules ()
toCategoryHtml p f t = do
route idRoute
compile $ do
u <- loadAll p
let ctx = listField f defaultContext (return u)
<> constField "title" (toUpper (head f) : tail f)
<> defaultContext
makeItem "" >>= loadAndApplyTemplate (fromFilePath $ "templates/"
++ t
++ "-list.html") ctx
>>= loadAndApplyTemplate "templates/default.html" ctx
>>= relativizeUrls
mdToHtml :: String -> Rules ()
mdToHtml t = do
route $ setExtension "html"
compile $ pandocCompiler
>>= loadAndApplyTemplate (fromFilePath $ "templates/" ++ t ++ ".html") defaultContext
>>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls
copyFiles :: Rules ()
copyFiles = route idRoute >> compile copyFileCompiler
filterType :: (Functor f, MonadMetadata f) => String -> [Item a] -> f [Item a]
filterType t = filterM ((\_ -> fmap (maybe False (== t)) .
flip getMetadataField "type" . itemIdentifier) t)
configuration :: Configuration
configuration =
defaultConfiguration {
deployCommand = unwords [synchCommand, synchTarget]
}