From 1075096df7268111b2de83f0c52af15921be4ca4 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Thu, 10 Feb 2011 15:08:26 +0100 Subject: Add sortByBaseName function for pages --- src/Hakyll/Web/Page.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Hakyll/Web/Page.hs') 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" -- cgit v1.2.3