@@ -11,7 +11,7 @@ import Hakyll.Web.Template (loadAndApplyTemplate)
11
11
import System.IO (SeekMode (RelativeSeek ))
12
12
import Hakyll.Web.Html.RelativizeUrls (relativizeUrls )
13
13
import Hakyll.Web.Template.Context (defaultContext )
14
- import Data.Maybe (isJust , fromJust )
14
+ import Data.Maybe (isJust , fromJust , fromMaybe )
15
15
16
16
--------------------------------------------------------------------------------------------------------
17
17
-- MAIN GENERATION -------------------------------------------------------------------------------------
@@ -39,7 +39,7 @@ main = hakyll $ do
39
39
create [" affiliates/index.html" ] $ do
40
40
route idRoute
41
41
compile $ do
42
- sponsors <- buildSponsorsCtx
42
+ sponsors <- buildBoilerplateCtx ( Just " Affiliates " )
43
43
ctx <- affiliatesCtx . sortOn itemIdentifier <$> loadAll " affiliates/*.markdown"
44
44
45
45
makeItem " "
@@ -52,7 +52,7 @@ main = hakyll $ do
52
52
create [" projects/index.html" ] $ do
53
53
route idRoute
54
54
compile $ do
55
- sponsors <- buildSponsorsCtx
55
+ sponsors <- buildBoilerplateCtx ( Just " Projects " )
56
56
ctx <- projectsCtx . sortOn itemIdentifier <$> loadAll " projects/*.markdown"
57
57
58
58
makeItem " "
@@ -78,7 +78,7 @@ main = hakyll $ do
78
78
create [" news/index.html" ] $ do
79
79
route idRoute
80
80
compile $ do
81
- sponsors <- buildSponsorsCtx
81
+ sponsors <- buildBoilerplateCtx ( Just " News " )
82
82
newsWithCategories <- recentFirst =<< loadAll " news/categories/**.html"
83
83
84
84
let ctx =
@@ -95,7 +95,7 @@ main = hakyll $ do
95
95
create [" news/press/index.html" ] $ do
96
96
route idRoute
97
97
compile $ do
98
- sponsors <- buildSponsorsCtx
98
+ sponsors <- buildBoilerplateCtx ( Just " Press " )
99
99
press <- recentFirst =<< loadAll " press/*.markdown"
100
100
101
101
let ctx =
@@ -112,7 +112,7 @@ main = hakyll $ do
112
112
create [" faq/index.html" ] $ do
113
113
route idRoute
114
114
compile $ do
115
- sponsors <- buildSponsorsCtx
115
+ sponsors <- buildBoilerplateCtx ( Just " FAQ " )
116
116
ctx <- faqCtx <$> loadAll " faq/*.markdown"
117
117
118
118
makeItem " "
@@ -125,7 +125,7 @@ main = hakyll $ do
125
125
create [" who-we-are/index.html" ] $ do
126
126
route idRoute
127
127
compile $ do
128
- sponsors <- buildSponsorsCtx
128
+ sponsors <- buildBoilerplateCtx ( Just " Who We Are " )
129
129
ctx <- whoWeAreCtx <$> loadAll " who-we-are/people/*.markdown"
130
130
131
131
makeItem " "
@@ -136,7 +136,7 @@ main = hakyll $ do
136
136
create [" who-we-are/past-boards/index.html" ] $ do
137
137
route idRoute
138
138
compile $ do
139
- sponsors <- buildSponsorsCtx
139
+ sponsors <- buildBoilerplateCtx ( Just " Past Boards " )
140
140
ctx <- whoWeAreCtx <$> loadAll " who-we-are/people/*.markdown"
141
141
142
142
makeItem " "
@@ -148,7 +148,7 @@ main = hakyll $ do
148
148
create [" podcast/index.html" ] $ do
149
149
route idRoute
150
150
compile $ do
151
- sponsors <- buildSponsorsCtx
151
+ sponsors <- buildBoilerplateCtx ( Just " Haskell Interlude " )
152
152
ctx <- podcastCtx <$> loadAll (" podcast/*/index.markdown" .&&. hasVersion " raw" )
153
153
154
154
makeItem " "
@@ -159,7 +159,7 @@ main = hakyll $ do
159
159
match " podcast/*/index.markdown" $ do
160
160
route $ setExtension " html"
161
161
compile $ do
162
- sponsors <- buildSponsorsCtx
162
+ sponsors <- buildBoilerplateCtx Nothing
163
163
-- extract the captures path fragment. really no easier way?
164
164
episode <- head . fromJust . capture " podcast/*/index.markdown" <$> getUnderlying
165
165
@@ -185,7 +185,7 @@ main = hakyll $ do
185
185
match (" index.html" .||. " **/index.html" ) $ do
186
186
route idRoute
187
187
compile $ do
188
- sponsors <- buildSponsorsCtx
188
+ sponsors <- buildBoilerplateCtx Nothing
189
189
getResourceBody
190
190
>>= applyAsTemplate sponsors
191
191
>>= loadAndApplyTemplate " templates/boilerplate.html" sponsors
@@ -196,7 +196,7 @@ main = hakyll $ do
196
196
create [" resources/index.html" ] $ do
197
197
route idRoute
198
198
compile $ do
199
- sponsors <- buildSponsorsCtx
199
+ sponsors <- buildBoilerplateCtx ( Just " Resources " )
200
200
resources <- loadAll " resources/*.markdown"
201
201
202
202
let ctx =
@@ -229,17 +229,23 @@ main = hakyll $ do
229
229
230
230
-- sponsors --------------------------------------------------------------------------------------------
231
231
232
- buildSponsorsCtx :: Compiler (Context String )
233
- buildSponsorsCtx = sponsorsCtx . sortOn itemIdentifier <$> loadAll " donations/sponsors/*.markdown"
232
+ buildBoilerplateCtx :: Maybe String -> Compiler (Context String )
233
+ buildBoilerplateCtx mtitle = boilerPlateCtx mtitle . sortOn itemIdentifier <$> loadAll " donations/sponsors/*.markdown"
234
234
235
235
-- | Partition sponsors into by level: monad, applicative, and functor
236
236
-- Sponsors are listed in the footer template, which means we need this
237
237
-- context for most pages.
238
- sponsorsCtx :: [Item String ] -> Context String
239
- sponsorsCtx sponsors =
238
+ --
239
+ -- We set the 'title' based on the title metadata for the item, if present,
240
+ -- or use the passed in Maybe title, if it is a Just, or "No title" if not.
241
+ boilerPlateCtx :: Maybe String -> [Item String ] -> Context String
242
+ boilerPlateCtx mtitle sponsors =
240
243
listField " monads" defaultContext (ofMetadataField " level" " Monad" sponsors) <>
241
244
listField " applicatives" defaultContext (ofMetadataField " level" " Applicative" sponsors) <>
242
245
listField " functors" defaultContext (ofMetadataField " level" " Functor" sponsors) <>
246
+ field " title" (\ item -> do
247
+ metadata <- getMetadata (itemIdentifier item)
248
+ return $ fromMaybe (fromMaybe " No title" mtitle) $ lookupString " title" metadata) <>
243
249
defaultContext
244
250
245
251
-- affiliates ------------------------------------------------------------------------------------------
@@ -314,7 +320,7 @@ whoWeAreCtx people =
314
320
) items'
315
321
316
322
-- podcast ---------------------------------------------------------------------------------------------
317
- podcastCtx :: [Item String ] -> Context String
323
+ podcastCtx :: [Item String ] -> Context String
318
324
podcastCtx episodes =
319
325
listField " episodes" defaultContext (return $ reverse episodes) <>
320
326
defaultContext
@@ -326,8 +332,8 @@ podcastCtx episodes =
326
332
-- | filter list of item string based on the given value to match on the given metadata field
327
333
ofMetadataField :: String -> String -> [Item String ] -> Compiler [Item String ]
328
334
ofMetadataField field value = filterM (\ item -> do
329
- mbStatus <- getMetadataField (itemIdentifier item) field
330
- return $ Just value == mbStatus
335
+ mbField <- getMetadataField (itemIdentifier item) field
336
+ return $ Just value == mbField
331
337
)
332
338
333
339
-- | sort list of item based on the given metadata field
0 commit comments