@@ -35,13 +35,17 @@ module Hakyll.Web.Tags
35 , renderTagList
35 , renderTagList
36 , renderTagsField
36 , renderTagsField
37 , renderCategoryField
37 , renderCategoryField
39+ , caseInsensitiveTags
40import Prelude hiding (id)
42import Prelude hiding (id)
41import Control.Category (id)
43import Control.Category (id)
42import Control.Applicative ((<$>))
44import Control.Applicative ((<$>))
45+import Data.Char (toLower)
46+import Data.Ord (comparing)
43import qualified Data.Map as M
47import qualified Data.Map as M
44−import Data.List (intersperse, intercalate)
48+import Data.List (intersperse, intercalate, sortBy)
45import Control.Arrow (arr, (&&&), (>>>), (***), (<<^), returnA)
49import Control.Arrow (arr, (&&&), (>>>), (***), (<<^), returnA)
46import Data.Maybe (catMaybes, fromMaybe)
50import Data.Maybe (catMaybes, fromMaybe)
47import Data.Monoid (mconcat)
51import Data.Monoid (mconcat)
@@ -206,3 +210,15 @@ renderCategoryField :: String -- ^ Destination key
206 -> (String -> Identifier a) -- ^ Create a category link
210 -> (String -> Identifier a) -- ^ Create a category link
207 -> Compiler (Page a) (Page a) -- ^ Resulting compiler
211 -> Compiler (Page a) (Page a) -- ^ Resulting compiler
208renderCategoryField = renderTagsFieldWith getCategory
212renderCategoryField = renderTagsFieldWith getCategory
214+-- | Sort tags using supplied function. First element of the tuple passed to
215+-- the comparing function is the actual tag name.
217+sortTagsBy :: ((String, [Page a]) -> (String, [Page a]) -> Ordering)
218+ -> Compiler (Tags a) (Tags a)
219+sortTagsBy f = arr $ Tags . sortBy f . tagsMap
221+-- | Sample sorting function that compares tags case insensitively.
223+caseInsensitiveTags :: (String, [Page a]) -> (String, [Page a]) -> Ordering
224+caseInsensitiveTags = comparing $ map toLower . fst