@@ -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,15 +17,18 @@ 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--------------------------------------------------------------------------------
25import Hakyll.Core.Compiler
28import Hakyll.Core.Compiler
26import Hakyll.Core.Identifier
29import Hakyll.Core.Identifier
27import Hakyll.Core.Item
30import Hakyll.Core.Item
31+import Hakyll.Core.Metadata
28import Hakyll.Web.Template
32import Hakyll.Web.Template
29import Hakyll.Web.Template.Context
33import Hakyll.Web.Template.Context
@@ -56,11 +60,15 @@ applyJoinTemplateList delimiter tpl context items = do
56-- | Sort pages chronologically. This function assumes that the pages have a
60-- | Sort pages chronologically. This function assumes that the pages have a
57-- @year-month-day-title.extension@ naming scheme -- as is the convention in
61-- @year-month-day-title.extension@ naming scheme -- as is the convention in
59−chronological :: [Item a] -> [Item a]
63+chronological :: MonadMetadata m => [Item a] -> m [Item a]
60−chronological = sortBy $ comparing $ takeBaseName . toFilePath . itemIdentifier
64+chronological =
61−
65+ sortByM $ getItemUTC defaultTimeLocale . itemIdentifier
67+ sortByM :: (Monad m, Ord k) => (a -> m k) -> [a] -> m [a]
68+ sortByM f xs = liftM (map fst . sortBy (comparing snd)) $
69+ mapM (\x -> liftM (x,) (f x)) xs
63--------------------------------------------------------------------------------
71--------------------------------------------------------------------------------
64-- | The reverse of 'chronological'
72-- | The reverse of 'chronological'
65−recentFirst :: [Item a] -> [Item a]
73+recentFirst :: (MonadMetadata m, Functor m) => [Item a] -> m [Item a]
66−recentFirst = reverse . chronological
74+recentFirst = fmap reverse . chronological