summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2012-01-25 01:58:45 -0800
committerJasper Van der Jeugt <jaspervdj@gmail.com>2012-01-25 01:58:45 -0800
commite12e64233d8937af38c4511387eace008bb4fa6b (patch)
tree301b47491750b5b50e4634b588a0ecf73d83f7ab /src
parentf90f29f096817aab9fba2f6c81fdbed8fcac8303 (diff)
parentdb03816b5a582de931cf6187fb656c23f81fc621 (diff)
downloadhakyll-e12e64233d8937af38c4511387eace008bb4fa6b.tar.gz
Merge pull request #52 from lubomir/master
Make sorting tags easier
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Web/Tags.hs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Hakyll/Web/Tags.hs b/src/Hakyll/Web/Tags.hs
index a5d4a9e..7c9abbb 100644
--- a/src/Hakyll/Web/Tags.hs
+++ b/src/Hakyll/Web/Tags.hs
@@ -35,13 +35,17 @@ module Hakyll.Web.Tags
, renderTagList
, renderTagsField
, renderCategoryField
+ , sortTagsBy
+ , caseInsensitiveTags
) where
import Prelude hiding (id)
import Control.Category (id)
import Control.Applicative ((<$>))
+import Data.Char (toLower)
+import Data.Ord (comparing)
import qualified Data.Map as M
-import Data.List (intersperse, intercalate)
+import Data.List (intersperse, intercalate, sortBy)
import Control.Arrow (arr, (&&&), (>>>), (***), (<<^), returnA)
import Data.Maybe (catMaybes, fromMaybe)
import Data.Monoid (mconcat)
@@ -206,3 +210,15 @@ renderCategoryField :: String -- ^ Destination key
-> (String -> Identifier a) -- ^ Create a category link
-> Compiler (Page a) (Page a) -- ^ Resulting compiler
renderCategoryField = renderTagsFieldWith getCategory
+
+-- | Sort tags using supplied function. First element of the tuple passed to
+-- the comparing function is the actual tag name.
+--
+sortTagsBy :: ((String, [Page a]) -> (String, [Page a]) -> Ordering)
+ -> Compiler (Tags a) (Tags a)
+sortTagsBy f = arr $ Tags . sortBy f . tagsMap
+
+-- | Sample sorting function that compares tags case insensitively.
+--
+caseInsensitiveTags :: (String, [Page a]) -> (String, [Page a]) -> Ordering
+caseInsensitiveTags = comparing $ map toLower . fst