forked from haskellfoundation/haskellfoundation.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.hs
345 lines (295 loc) · 16.3 KB
/
site.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
{-# Language ScopedTypeVariables #-}
{-# Language OverloadedStrings #-}
{-# Language ViewPatterns #-}
{-# Language BangPatterns #-}
import Hakyll
import Data.List (sortOn)
import Control.Monad (filterM)
import Control.Monad.ListM (sortByM)
import Hakyll.Web.Template (loadAndApplyTemplate)
import System.IO (SeekMode(RelativeSeek))
import Hakyll.Web.Html.RelativizeUrls (relativizeUrls)
import Hakyll.Web.Template.Context (defaultContext)
import Data.Maybe (isJust, fromJust, fromMaybe)
--------------------------------------------------------------------------------------------------------
-- MAIN GENERATION -------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------
main :: IO ()
main = hakyll $ do
-- statics ---------------------------------------------------------------------------------------------
match "assets/css/main.css" $ do
route idRoute
compile compressCssCompiler
match "assets/**" $ do
route idRoute
compile copyFileCompiler
match "sw.js" $ do
route idRoute
compile copyFileCompiler
-- sponsors --------------------------------------------------------------------------------------------
match "donations/sponsors/*.markdown" $ compile pandocCompiler
-- affiliates ------------------------------------------------------------------------------------------
match "affiliates/*.markdown" $ compile pandocCompiler
create ["affiliates/index.html"] $ do
route idRoute
compile $ do
sponsors <- buildBoilerplateCtx (Just "Affiliates")
ctx <- affiliatesCtx . sortOn itemIdentifier <$> loadAll "affiliates/*.markdown"
makeItem ""
>>= loadAndApplyTemplate "templates/affiliates/list.html" ctx
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
-- projects --------------------------------------------------------------------------------------------
match "projects/*.markdown" $ compile pandocCompiler
create ["projects/index.html"] $ do
route idRoute
compile $ do
sponsors <- buildBoilerplateCtx (Just "Projects")
ctx <- projectsCtx . sortOn itemIdentifier <$> loadAll "projects/*.markdown"
makeItem ""
>>= loadAndApplyTemplate "templates/projects/list.html" ctx
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
-- news ------------------------------------------------------------------------------------------------
match "news/**.markdown" $ compile pandocCompiler
categories <- buildCategories "news/**.markdown" (fromCapture "news/categories/**.html")
tagsRules categories $ \category catId -> compile $ do
news <- recentFirst =<< loadAll catId
let ctx =
listField "news" (newsWithCategoriesCtx categories) (pure news) <>
dateField "category" "%B %e, %Y" <>
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/news/tile.html" ctx
>>= relativizeUrls
create ["news/index.html"] $ do
route idRoute
compile $ do
sponsors <- buildBoilerplateCtx (Just "News")
newsWithCategories <- recentFirst =<< loadAll "news/categories/**.html"
let ctx =
listField "categories" defaultContext (return newsWithCategories) <>
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/news/list.html" ctx
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
-- press -----------------------------------------------------------------------------------------------
match "press/**.markdown" $ compile pandocCompiler
create ["news/press/index.html"] $ do
route idRoute
compile $ do
sponsors <- buildBoilerplateCtx (Just "Press")
press <- recentFirst =<< loadAll "press/*.markdown"
let ctx =
listField "press_articles" defaultContext (return press) <>
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/press/list.html" ctx
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
-- faq ------------------------------------------------------------------------------------------------
match "faq/*.markdown" $ compile pandocCompiler
create ["faq/index.html"] $ do
route idRoute
compile $ do
sponsors <- buildBoilerplateCtx (Just "FAQ")
ctx <- faqCtx <$> loadAll "faq/*.markdown"
makeItem ""
>>= loadAndApplyTemplate "templates/faq/list.html" ctx
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
-- who we are ------------------------------------------------------------------------------------------
match "who-we-are/people/*.markdown" $ compile pandocCompiler
create ["who-we-are/index.html"] $ do
route idRoute
compile $ do
sponsors <- buildBoilerplateCtx (Just "Who We Are")
ctx <- whoWeAreCtx <$> loadAll "who-we-are/people/*.markdown"
makeItem ""
>>= loadAndApplyTemplate "templates/who-we-are/exec-and-board.html" ctx
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
create ["who-we-are/past-boards/index.html"] $ do
route idRoute
compile $ do
sponsors <- buildBoilerplateCtx (Just "Past Boards")
ctx <- whoWeAreCtx <$> loadAll "who-we-are/people/*.markdown"
makeItem ""
>>= loadAndApplyTemplate "templates/who-we-are/past-board.html" ctx
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
-- podcast ---------------------------------------------------------------------------------------------
create ["podcast/index.html"] $ do
route idRoute
compile $ do
sponsors <- buildBoilerplateCtx (Just "Haskell Interlude")
ctx <- podcastCtx <$> loadAll ("podcast/*/index.markdown" .&&. hasVersion "raw")
makeItem ""
>>= loadAndApplyTemplate "templates/podcast/list.html" ctx
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
match "podcast/*/index.markdown" $ do
route $ setExtension "html"
compile $ do
sponsors <- buildBoilerplateCtx Nothing
-- extract the captures path fragment. really no easier way?
episode <- head . fromJust . capture "podcast/*/index.markdown" <$> getUnderlying
let ctxt = mconcat
[ field "transcript" $ \_ -> do
loadBody (fromCaptures "podcast/*/transcript.markdown" [episode])
, field "links" $ \_ -> do
loadBody (fromCaptures "podcast/*/links.markdown" [episode])
, defaultContext
]
pandocCompiler
>>= applyAsTemplate sponsors
>>= loadAndApplyTemplate "templates/podcast/episode.html" ctxt
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
match "podcast/*/index.markdown" $ version "raw" $ compile pandocCompiler
match "podcast/*/transcript.markdown" $ compile pandocCompiler
match "podcast/*/links.markdown" $ compile pandocCompiler
-- general 'static' pages ------------------------------------------------------------------------------
match ("index.html" .||. "**/index.html") $ do
route idRoute
compile $ do
sponsors <- buildBoilerplateCtx Nothing
getResourceBody
>>= applyAsTemplate sponsors
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
-- resources -------------------------------------------------------------------------------------------
match "resources/*.markdown" $ compile pandocCompiler
create ["resources/index.html"] $ do
route idRoute
compile $ do
sponsors <- buildBoilerplateCtx (Just "Resources")
resources <- loadAll "resources/*.markdown"
let ctx =
listField "resources" defaultContext (return resources) <>
defaultContext
makeItem ""
>>= loadAndApplyTemplate "templates/resources/list.html" ctx
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
-- 404 -------------------------------------------------------------------------------------------------
match "404.html" $ do
route idRoute
compile $ do
sponsors <- buildBoilerplateCtx Nothing
getResourceBody
>>= applyAsTemplate sponsors
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
>>= relativizeUrls
-- templates -------------------------------------------------------------------------------------------
match "templates/*" $ compile templateBodyCompiler
match "templates/**" $ compile templateBodyCompiler
--------------------------------------------------------------------------------------------------------
-- CONTEXT ---------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------
-- sponsors --------------------------------------------------------------------------------------------
buildBoilerplateCtx :: Maybe String -> Compiler (Context String)
buildBoilerplateCtx mtitle = boilerPlateCtx mtitle . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
-- | Partition sponsors into by level: monad, applicative, and functor
-- Sponsors are listed in the footer template, which means we need this
-- context for most pages.
--
-- We set the 'title' based on the title metadata for the item, if present,
-- or use the passed in Maybe title, if it is a Just, or "No title" if not.
boilerPlateCtx :: Maybe String -> [Item String] -> Context String
boilerPlateCtx mtitle sponsors =
listField "monads" defaultContext (ofMetadataField "level" "Monad" sponsors) <>
listField "applicatives" defaultContext (ofMetadataField "level" "Applicative" sponsors) <>
listField "functors" defaultContext (ofMetadataField "level" "Functor" sponsors) <>
field "title" (\item -> do
metadata <- getMetadata (itemIdentifier item)
return $ fromMaybe (fromMaybe "No title" mtitle) $ lookupString "title" metadata) <>
defaultContext
-- affiliates ------------------------------------------------------------------------------------------
-- | Partition affiliates into affiliates and pending
affiliatesCtx :: [Item String] -> Context String
affiliatesCtx affiliates =
listField "affiliated" defaultContext (ofMetadataField "status" "affiliated" affiliates) <>
listField "pending" defaultContext (ofMetadataField "status" "pending" affiliates) <>
defaultContext
-- projects --------------------------------------------------------------------------------------------
-- | Partition projects into : Ideation | Proposed | In Progress | Completed
projectsCtx :: [Item String] -> Context String
projectsCtx projects =
listField "ideas" defaultContext (ofMetadataField "status" "ideation" projects) <>
listField "proposals" defaultContext (ofMetadataField "status" "proposed" projects) <>
listField "inprogress" defaultContext (ofMetadataField "status" "inprogress" projects) <>
listField "completed" defaultContext (ofMetadataField "status" "completed" projects) <>
defaultContext
-- news ------------------------------------------------------------------------------------------------
-- | build group of news inside date of publishing (category)
newsWithCategoriesCtx :: Tags -> Context String
newsWithCategoriesCtx categories =
listField "categories" categoryCtx getAllCategories <>
defaultContext
where
getAllCategories :: Compiler [Item (String, [Identifier])]
getAllCategories = pure . map buildItemFromTag $ tagsMap categories
where
buildItemFromTag :: (String, [Identifier]) -> Item (String, [Identifier])
buildItemFromTag c@(name, _) = Item (tagsMakeId categories name) c
categoryCtx :: Context (String, [Identifier])
categoryCtx =
listFieldWith "news" newsCtx getNews <>
metadataField <>
urlField "url" <>
pathField "path" <>
titleField "title" <>
missingField
where
getNews:: Item (String, [Identifier]) -> Compiler [Item String]
getNews (itemBody -> (_, ids)) = mapM load ids
newsCtx :: Context String
newsCtx = newsWithCategoriesCtx categories
-- faq -------------------------------------------------------------------------------------------------
faqCtx :: [Item String] -> Context String
faqCtx entries =
listField "faq_entries" defaultContext (sortFromMetadataField "order" entries) <>
defaultContext
-- who we are ------------------------------------------------------------------------------------------
whoWeAreCtx :: [Item String] -> Context String
whoWeAreCtx people =
listField "currentexecutiveteam" defaultContext (ofMetadataFieldCurrent True "executiveTeam" "True" people) <>
listField "currentboard" defaultContext (ofMetadataFieldCurrent True "executiveTeam" "False" people) <>
listField "pastexecutiveteam" defaultContext (ofMetadataFieldCurrent False "executiveTeam" "True" people) <>
listField "pastboard" defaultContext (ofMetadataFieldCurrent False "executiveTeam" "False" people) <>
listField "interimboard" defaultContext (ofMetadataField "interimBoard" "True" people) <>
defaultContext
where
ofMetadataFieldCurrent :: Bool -> String -> String -> [Item String] -> Compiler [Item String]
ofMetadataFieldCurrent cur field value items = do
items' <- ofMetadataField field value items
filterM (\item -> do
mbTenureStart <- getMetadataField (itemIdentifier item) "tenureStart"
mbTenureStop <- getMetadataField (itemIdentifier item) "tenureEnd"
pure $ case mbTenureStop of
Nothing -> cur && isJust mbTenureStart
Just date -> not cur
) items'
-- podcast ---------------------------------------------------------------------------------------------
podcastCtx :: [Item String] -> Context String
podcastCtx episodes =
listField "episodes" defaultContext (return $ reverse episodes) <>
defaultContext
--------------------------------------------------------------------------------------------------------
-- UTILS -----------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------
-- | filter list of item string based on the given value to match on the given metadata field
ofMetadataField :: String -> String -> [Item String] -> Compiler [Item String]
ofMetadataField field value = filterM (\item -> do
mbField <- getMetadataField (itemIdentifier item) field
return $ Just value == mbField
)
-- | sort list of item based on the given metadata field
sortFromMetadataField :: String -> [Item String] -> Compiler [Item String]
sortFromMetadataField field = sortByM (\a b -> do
a' <- getMetadataField (itemIdentifier a) field
b' <- getMetadataField (itemIdentifier b) field
return $ compare a' b'
)