3
3
{-# Language ViewPatterns #-}
4
4
5
5
import Hakyll
6
- import Control.Monad (filterM )
7
6
import Data.List (sortOn )
7
+ import Control.Monad (filterM )
8
+ import Control.Monad.ListM (sortByM )
8
9
9
10
--------------------------------------------------------------------------------------------------------
10
11
-- MAIN GENERATION -------------------------------------------------------------------------------------
@@ -112,11 +113,7 @@ main = hakyll $ do
112
113
route idRoute
113
114
compile $ do
114
115
sponsors <- sponsorsCtx . sortOn itemIdentifier <$> loadAll " donations/sponsors/*.markdown"
115
- entries <- loadAll " faq/*.markdown"
116
-
117
- let ctx =
118
- listField " faq_entries" defaultContext (return entries) <>
119
- defaultContext
116
+ ctx <- faqCtx <$> loadAll " faq/*.markdown"
120
117
121
118
makeItem " "
122
119
>>= loadAndApplyTemplate " templates/faq/list.html" ctx
@@ -187,6 +184,12 @@ newsWithCategoriesCtx categories =
187
184
newsCtx :: Context String
188
185
newsCtx = newsWithCategoriesCtx categories
189
186
187
+ -- faq -------------------------------------------------------------------------------------------------
188
+ faqCtx :: [Item String ] -> Context String
189
+ faqCtx entries =
190
+ listField " faq_entries" defaultContext (sortFromMetadataField " order" entries) <>
191
+ defaultContext
192
+
190
193
--------------------------------------------------------------------------------------------------------
191
194
-- UTILS -----------------------------------------------------------------------------------------------
192
195
--------------------------------------------------------------------------------------------------------
@@ -197,3 +200,11 @@ ofMetadataField field value = filterM (\item -> do
197
200
mbStatus <- getMetadataField (itemIdentifier item) field
198
201
return $ Just value == mbStatus
199
202
)
203
+
204
+ -- | sort list of item based on the given metadata field
205
+ sortFromMetadataField :: String -> [Item String ] -> Compiler [Item String ]
206
+ sortFromMetadataField field = sortByM (\ a b -> do
207
+ a' <- getMetadataField (itemIdentifier a) field
208
+ b' <- getMetadataField (itemIdentifier b) field
209
+ return $ compare a' b'
210
+ )
0 commit comments