Skip to content

Commit d41ad00

Browse files
committed
fix: factorize sponsors and simplify resources ctx
1 parent f23cdc8 commit d41ad00

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

site.hs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ main = hakyll $ do
2525
match "index.html" $ do
2626
route idRoute
2727
compile $ do
28-
sponsors <- sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
28+
sponsors <- buildSponsorsCtx
2929
getResourceBody
3030
>>= applyAsTemplate sponsors
3131
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
@@ -39,7 +39,7 @@ main = hakyll $ do
3939
create ["affiliates/index.html"] $ do
4040
route idRoute
4141
compile $ do
42-
sponsors <- sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
42+
sponsors <- buildSponsorsCtx
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 <- sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
55+
sponsors <- buildSponsorsCtx
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 <- sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
81+
sponsors <- buildSponsorsCtx
8282
newsWithCategories <- recentFirst =<< loadAll "news/categories/**.html"
8383

8484
let ctx =
@@ -95,15 +95,15 @@ main = hakyll $ do
9595
create ["news/press/index.html"] $ do
9696
route idRoute
9797
compile $ do
98-
sponsors <- sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
98+
sponsors <- buildSponsorsCtx
9999
press <- recentFirst =<< loadAll "press/*.markdown"
100100

101101
let ctx =
102102
listField "press_articles" defaultContext (return press) <>
103103
defaultContext
104104

105105
makeItem ""
106-
>>= loadAndApplyTemplate "templates/press/list.html" ctx
106+
>>= loadAndApplyTemplate "templates/press/list.html" ctx
107107
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
108108
>>= relativizeUrls
109109

@@ -112,7 +112,7 @@ main = hakyll $ do
112112
create ["faq/index.html"] $ do
113113
route idRoute
114114
compile $ do
115-
sponsors <- sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
115+
sponsors <- buildSponsorsCtx
116116
ctx <- faqCtx <$> loadAll "faq/*.markdown"
117117

118118
makeItem ""
@@ -125,12 +125,16 @@ main = hakyll $ do
125125
create ["resources/index.html"] $ do
126126
route idRoute
127127
compile $ do
128-
sponsors <- sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
129-
ctx <- resourcesCtx <$> loadAll "resources/*.markdown"
128+
sponsors <- buildSponsorsCtx
129+
resources <- loadAll "resources/*.markdown"
130+
131+
let ctx =
132+
listField "resources" defaultContext (return resources) <>
133+
defaultContext
130134

131135
makeItem ""
132-
>>= loadAndApplyTemplate "templates/resources/list.html" ctx
133-
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
136+
>>= loadAndApplyTemplate "templates/resources/list.html" ctx
137+
>>= loadAndApplyTemplate "templates/boilerplate.html" sponsors
134138
>>= relativizeUrls
135139

136140
-- templates -------------------------------------------------------------------------------------------
@@ -143,6 +147,10 @@ main = hakyll $ do
143147
--------------------------------------------------------------------------------------------------------
144148

145149
-- sponsors --------------------------------------------------------------------------------------------
150+
151+
buildSponsorsCtx :: Compiler (Context String)
152+
buildSponsorsCtx = sponsorsCtx . sortOn itemIdentifier <$> loadAll "donations/sponsors/*.markdown"
153+
146154
-- | Partition sponsors into by level: monad, applicative, and functor
147155
-- Sponsors are listed in the footer template, which means we need this
148156
-- context for most pages.
@@ -203,12 +211,6 @@ faqCtx entries =
203211
listField "faq_entries" defaultContext (sortFromMetadataField "order" entries) <>
204212
defaultContext
205213

206-
-- resources -------------------------------------------------------------------------------------------
207-
resourcesCtx :: [Item String] -> Context String
208-
resourcesCtx resources =
209-
listField "resources" defaultContext (return resources) <>
210-
defaultContext
211-
212214
--------------------------------------------------------------------------------------------------------
213215
-- UTILS -----------------------------------------------------------------------------------------------
214216
--------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)