@@ -10,6 +10,7 @@ module Hakyll.Web.Page
1010 , toMap
1111 , pageRead
1212 , addDefaultFields
13+ , sortByBaseName
1314 ) where
1415
1516import Prelude hiding (id)
@@ -19,6 +20,8 @@ import System.FilePath (takeBaseName, takeDirectory)
1920import Data.Monoid (Monoid, mempty)
2021import Data.Map (Map)
2122import qualified Data.Map as M
23+import Data.List (sortBy)
24+import Data.Ord (comparing)
2225
2326import Hakyll.Core.Identifier
2427import Hakyll.Core.Compiler
@@ -71,3 +74,10 @@ addDefaultFields = (getRoute &&& id >>^ uncurry addRoute)
7174 . setField "path" p
7275 where
7376 p = toFilePath i
77+
78+-- | Sort posts based on the basename of the post. This is equivalent to a
79+-- chronologival sort, because of the @year-month-day-title.extension@ naming
80+-- convention in Hakyll.
81+--
82+sortByBaseName :: [Page a] -> [Page a]
83+sortByBaseName = sortBy $ comparing $ takeBaseName . getField "path"