@@ -1,3 +1,4 @@
1+{-# LANGUAGE TupleSections #-}
12--------------------------------------------------------------------------------
23-- | Provides an easy way to combine several items in a list. The applications
34-- are obvious:
@@ -16,9 +17,11 @@ module Hakyll.Web.Template.List
1617
1718
1819--------------------------------------------------------------------------------
20+import Control.Monad (liftM)
1921import Data.List (intersperse, sortBy)
2022import Data.Ord (comparing)
2123import System.FilePath (takeBaseName)
24+import System.Locale (defaultTimeLocale)
2225
2326
2427--------------------------------------------------------------------------------
@@ -56,11 +59,13 @@ applyJoinTemplateList delimiter tpl context items = do
5659-- | Sort pages chronologically. This function assumes that the pages have a
5760-- @year-month-day-title.extension@ naming scheme -- as is the convention in
5861-- Hakyll.
59−chronological :: [Item a] -> [Item a]
60−chronological = sortBy $ comparing $ takeBaseName . toFilePath . itemIdentifier
61−
62+chronological :: [Item a] -> Compiler [Item a]
63+chronological = sortByM $ getItemUTC defaultTimeLocale . itemIdentifier
64+ where sortByM :: (Monad m, Ord k) => (a -> m k) -> [a] -> m [a]
65+ sortByM f xs = liftM (map fst . sortBy (comparing snd)) $
66+ mapM (\x -> liftM (x,) (f x)) xs
6267
6368--------------------------------------------------------------------------------
6469-- | The reverse of 'chronological'
65−recentFirst :: [Item a] -> [Item a]
66−recentFirst = reverse . chronological
70+recentFirst :: [Item a] -> Compiler [Item a]
71+recentFirst i = return . reverse =<< chronological i