summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Web/Page.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Hakyll/Web/Page.hs b/src/Hakyll/Web/Page.hs
index c7de026..549badc 100644
--- a/src/Hakyll/Web/Page.hs
+++ b/src/Hakyll/Web/Page.hs
@@ -10,6 +10,7 @@ module Hakyll.Web.Page
, toMap
, pageRead
, addDefaultFields
+ , sortByBaseName
) where
import Prelude hiding (id)
@@ -19,6 +20,8 @@ import System.FilePath (takeBaseName, takeDirectory)
import Data.Monoid (Monoid, mempty)
import Data.Map (Map)
import qualified Data.Map as M
+import Data.List (sortBy)
+import Data.Ord (comparing)
import Hakyll.Core.Identifier
import Hakyll.Core.Compiler
@@ -71,3 +74,10 @@ addDefaultFields = (getRoute &&& id >>^ uncurry addRoute)
. setField "path" p
where
p = toFilePath i
+
+-- | Sort posts based on the basename of the post. This is equivalent to a
+-- chronologival sort, because of the @year-month-day-title.extension@ naming
+-- convention in Hakyll.
+--
+sortByBaseName :: [Page a] -> [Page a]
+sortByBaseName = sortBy $ comparing $ takeBaseName . getField "path"