@@ -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 =
@@ -219,17 +219,23 @@ main = hakyll $ do
219
219
220
220
-- sponsors --------------------------------------------------------------------------------------------
221
221
222
- buildSponsorsCtx :: Compiler (Context String )
223
- buildSponsorsCtx = sponsorsCtx . sortOn itemIdentifier <$> loadAll " donations/sponsors/*.markdown"
222
+ buildBoilerplateCtx :: Maybe String -> Compiler (Context String )
223
+ buildBoilerplateCtx mtitle = boilerPlateCtx mtitle . sortOn itemIdentifier <$> loadAll " donations/sponsors/*.markdown"
224
224
225
225
-- | Partition sponsors into by level: monad, applicative, and functor
226
226
-- Sponsors are listed in the footer template, which means we need this
227
227
-- context for most pages.
228
- sponsorsCtx :: [Item String ] -> Context String
229
- sponsorsCtx sponsors =
228
+ --
229
+ -- We set the 'title' based on the title metadata for the item, if present,
230
+ -- or use the passed in Maybe title, if it is a Just, or "No title" if not.
231
+ boilerPlateCtx :: Maybe String -> [Item String ] -> Context String
232
+ boilerPlateCtx mtitle sponsors =
230
233
listField " monads" defaultContext (ofMetadataField " level" " Monad" sponsors) <>
231
234
listField " applicatives" defaultContext (ofMetadataField " level" " Applicative" sponsors) <>
232
235
listField " functors" defaultContext (ofMetadataField " level" " Functor" sponsors) <>
236
+ field " title" (\ item -> do
237
+ metadata <- getMetadata (itemIdentifier item)
238
+ return $ fromMaybe (fromMaybe " No title" mtitle) $ lookupString " title" metadata) <>
233
239
defaultContext
234
240
235
241
-- affiliates ------------------------------------------------------------------------------------------
@@ -304,7 +310,7 @@ whoWeAreCtx people =
304
310
) items'
305
311
306
312
-- podcast ---------------------------------------------------------------------------------------------
307
- podcastCtx :: [Item String ] -> Context String
313
+ podcastCtx :: [Item String ] -> Context String
308
314
podcastCtx episodes =
309
315
listField " episodes" defaultContext (return $ reverse episodes) <>
310
316
defaultContext
@@ -316,8 +322,8 @@ podcastCtx episodes =
316
322
-- | filter list of item string based on the given value to match on the given metadata field
317
323
ofMetadataField :: String -> String -> [Item String ] -> Compiler [Item String ]
318
324
ofMetadataField field value = filterM (\ item -> do
319
- mbStatus <- getMetadataField (itemIdentifier item) field
320
- return $ Just value == mbStatus
325
+ mbField <- getMetadataField (itemIdentifier item) field
326
+ return $ Just value == mbField
321
327
)
322
328
323
329
-- | sort list of item based on the given metadata field
0 commit comments