Skip to content

Commit f4bf42e

Browse files
authored
Merge pull request #159 from haskellfoundation/titles
Provide a `title` value for `create`d pages.
2 parents 27d0893 + c5b631e commit f4bf42e

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

site.hs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Hakyll.Web.Template (loadAndApplyTemplate)
1111
import System.IO (SeekMode(RelativeSeek))
1212
import Hakyll.Web.Html.RelativizeUrls (relativizeUrls)
1313
import Hakyll.Web.Template.Context (defaultContext)
14-
import Data.Maybe (isJust, fromJust)
14+
import Data.Maybe (isJust, fromJust, fromMaybe)
1515

1616
--------------------------------------------------------------------------------------------------------
1717
-- MAIN GENERATION -------------------------------------------------------------------------------------
@@ -39,7 +39,7 @@ main = hakyll $ do
3939
create ["affiliates/index.html"] $ do
4040
route idRoute
4141
compile $ do
42-
sponsors <- buildSponsorsCtx
42+
sponsors <- buildBoilerplateCtx (Just "Affiliates")
4343
ctx <- affiliatesCtx . sortOn itemIdentifier <$> loadAll "affiliates/*.markdown"
4444

4545
makeItem ""
@@ -52,7 +52,7 @@ main = hakyll $ do
5252
create ["projects/index.html"] $ do
5353
route idRoute
5454
compile $ do
55-
sponsors <- buildSponsorsCtx
55+
sponsors <- buildBoilerplateCtx (Just "Projects")
5656
ctx <- projectsCtx . sortOn itemIdentifier <$> loadAll "projects/*.markdown"
5757

5858
makeItem ""
@@ -78,7 +78,7 @@ main = hakyll $ do
7878
create ["news/index.html"] $ do
7979
route idRoute
8080
compile $ do
81-
sponsors <- buildSponsorsCtx
81+
sponsors <- buildBoilerplateCtx (Just "News")
8282
newsWithCategories <- recentFirst =<< loadAll "news/categories/**.html"
8383

8484
let ctx =
@@ -95,7 +95,7 @@ main = hakyll $ do
9595
create ["news/press/index.html"] $ do
9696
route idRoute
9797
compile $ do
98-
sponsors <- buildSponsorsCtx
98+
sponsors <- buildBoilerplateCtx (Just "Press")
9999
press <- recentFirst =<< loadAll "press/*.markdown"
100100

101101
let ctx =
@@ -112,7 +112,7 @@ main = hakyll $ do
112112
create ["faq/index.html"] $ do
113113
route idRoute
114114
compile $ do
115-
sponsors <- buildSponsorsCtx
115+
sponsors <- buildBoilerplateCtx (Just "FAQ")
116116
ctx <- faqCtx <$> loadAll "faq/*.markdown"
117117

118118
makeItem ""
@@ -125,7 +125,7 @@ main = hakyll $ do
125125
create ["who-we-are/index.html"] $ do
126126
route idRoute
127127
compile $ do
128-
sponsors <- buildSponsorsCtx
128+
sponsors <- buildBoilerplateCtx (Just "Who We Are")
129129
ctx <- whoWeAreCtx <$> loadAll "who-we-are/people/*.markdown"
130130

131131
makeItem ""
@@ -136,7 +136,7 @@ main = hakyll $ do
136136
create ["who-we-are/past-boards/index.html"] $ do
137137
route idRoute
138138
compile $ do
139-
sponsors <- buildSponsorsCtx
139+
sponsors <- buildBoilerplateCtx (Just "Past Boards")
140140
ctx <- whoWeAreCtx <$> loadAll "who-we-are/people/*.markdown"
141141

142142
makeItem ""
@@ -148,7 +148,7 @@ main = hakyll $ do
148148
create ["podcast/index.html"] $ do
149149
route idRoute
150150
compile $ do
151-
sponsors <- buildSponsorsCtx
151+
sponsors <- buildBoilerplateCtx (Just "Haskell Interlude")
152152
ctx <- podcastCtx <$> loadAll ("podcast/*/index.markdown" .&&. hasVersion "raw")
153153

154154
makeItem ""
@@ -159,7 +159,7 @@ main = hakyll $ do
159159
match "podcast/*/index.markdown" $ do
160160
route $ setExtension "html"
161161
compile $ do
162-
sponsors <- buildSponsorsCtx
162+
sponsors <- buildBoilerplateCtx Nothing
163163
-- extract the captures path fragment. really no easier way?
164164
episode <- head . fromJust . capture "podcast/*/index.markdown" <$> getUnderlying
165165

@@ -185,7 +185,7 @@ main = hakyll $ do
185185
match ("index.html" .||. "**/index.html") $ do
186186
route idRoute
187187
compile $ do
188-
sponsors <- buildSponsorsCtx
188+
sponsors <- buildBoilerplateCtx Nothing
189189
getResourceBody
190190
>>= applyAsTemplate sponsors
191191
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
@@ -196,7 +196,7 @@ main = hakyll $ do
196196
create ["resources/index.html"] $ do
197197
route idRoute
198198
compile $ do
199-
sponsors <- buildSponsorsCtx
199+
sponsors <- buildBoilerplateCtx (Just "Resources")
200200
resources <- loadAll "resources/*.markdown"
201201

202202
let ctx =
@@ -229,17 +229,23 @@ main = hakyll $ do
229229

230230
-- sponsors --------------------------------------------------------------------------------------------
231231

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"
234234

235235
-- | Partition sponsors into by level: monad, applicative, and functor
236236
-- Sponsors are listed in the footer template, which means we need this
237237
-- 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 =
240243
listField "monads" defaultContext (ofMetadataField "level" "Monad" sponsors) <>
241244
listField "applicatives" defaultContext (ofMetadataField "level" "Applicative" sponsors) <>
242245
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) <>
243249
defaultContext
244250

245251
-- affiliates ------------------------------------------------------------------------------------------
@@ -314,7 +320,7 @@ whoWeAreCtx people =
314320
) items'
315321

316322
-- podcast ---------------------------------------------------------------------------------------------
317-
podcastCtx :: [Item String] -> Context String
323+
podcastCtx :: [Item String] -> Context String
318324
podcastCtx episodes =
319325
listField "episodes" defaultContext (return $ reverse episodes) <>
320326
defaultContext
@@ -326,8 +332,8 @@ podcastCtx episodes =
326332
-- | filter list of item string based on the given value to match on the given metadata field
327333
ofMetadataField :: String -> String -> [Item String] -> Compiler [Item String]
328334
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
331337
)
332338

333339
-- | sort list of item based on the given metadata field

0 commit comments

Comments
 (0)