@@ -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,15 +17,18 @@ 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--------------------------------------------------------------------------------
2528import Hakyll.Core.Compiler
2629import Hakyll.Core.Identifier
2730import Hakyll.Core.Item
31+import Hakyll.Core.Metadata
2832import Hakyll.Web.Template
2933import Hakyll.Web.Template.Context
3034
@@ -56,11 +60,15 @@ applyJoinTemplateList delimiter tpl context items = do
5660-- | Sort pages chronologically. This function assumes that the pages have a
5761-- @year-month-day-title.extension@ naming scheme -- as is the convention in
5862-- Hakyll.
59−chronological :: [Item a] -> [Item a]
60−chronological = sortBy $ comparing $ takeBaseName . toFilePath . itemIdentifier
61−
63+chronological :: MonadMetadata m => [Item a] -> m [Item a]
64+chronological =
65+ sortByM $ getItemUTC defaultTimeLocale . itemIdentifier
66+ where
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
6270
6371--------------------------------------------------------------------------------
6472-- | The reverse of 'chronological'
65−recentFirst :: [Item a] -> [Item a]
66−recentFirst = reverse . chronological
73+recentFirst :: (MonadMetadata m, Functor m) => [Item a] -> m [Item a]
74+recentFirst = fmap reverse . chronological