@@ -1,3 +1,4 @@
1+{-# LANGUAGE TupleSections #-}
1--------------------------------------------------------------------------------
2--------------------------------------------------------------------------------
2-- | Provides an easy way to combine several items in a list. The applications
3-- | Provides an easy way to combine several items in a list. The applications
3-- are obvious:
4-- are obvious:
@@ -16,9 +17,11 @@ module Hakyll.Web.Template.List
18--------------------------------------------------------------------------------
19--------------------------------------------------------------------------------
20+import Control.Monad (liftM)
19import Data.List (intersperse, sortBy)
21import Data.List (intersperse, sortBy)
20import Data.Ord (comparing)
22import Data.Ord (comparing)
21import System.FilePath (takeBaseName)
23import System.FilePath (takeBaseName)
24+import System.Locale (defaultTimeLocale)
24--------------------------------------------------------------------------------
27--------------------------------------------------------------------------------
@@ -56,11 +59,13 @@ applyJoinTemplateList delimiter tpl context items = do
56-- | Sort pages chronologically. This function assumes that the pages have a
59-- | Sort pages chronologically. This function assumes that the pages have a
57-- @year-month-day-title.extension@ naming scheme -- as is the convention in
60-- @year-month-day-title.extension@ naming scheme -- as is the convention in
59−chronological :: [Item a] -> [Item a]
62+chronological :: [Item a] -> Compiler [Item a]
60−chronological = sortBy $ comparing $ takeBaseName . toFilePath . itemIdentifier
63+chronological = sortByM $ getItemUTC defaultTimeLocale . itemIdentifier
61−
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
63--------------------------------------------------------------------------------
68--------------------------------------------------------------------------------
64-- | The reverse of 'chronological'
69-- | The reverse of 'chronological'
65−recentFirst :: [Item a] -> [Item a]
70+recentFirst :: [Item a] -> Compiler [Item a]
66−recentFirst = reverse . chronological
71+recentFirst i = return . reverse =<< chronological i