on master help sign in
Assoc. list-based implementation of tags
8b5347eJasper Van der Jeugt
src/Hakyll/Web/Tags.hs+4−4
@@ -40,7 +40,6 @@ module Hakyll.Web.Tags
40import Prelude hiding (id)
40import Prelude hiding (id)
41import Control.Category (id)
41import Control.Category (id)
42import Control.Applicative ((<$>))
42import Control.Applicative ((<$>))
43−import Data.Map (Map)
44import qualified Data.Map as M
43import qualified Data.Map as M
45import Data.List (intersperse, intercalate)
44import Data.List (intersperse, intercalate)
46import Control.Arrow (arr, (&&&), (>>>), (***), (<<^), returnA)
45import Control.Arrow (arr, (&&&), (>>>), (***), (<<^), returnA)
@@ -65,7 +64,7 @@ import Hakyll.Core.Util.String
65-- | Data about tags
64-- | Data about tags
66--
65--
67data Tags a = Tags
66data Tags a = Tags
68− { tagsMap :: Map String [Page a]
67+ { tagsMap :: [(String, [Page a])]
69 } deriving (Show, Typeable)
68 } deriving (Show, Typeable)
70
69
71instance Binary a => Binary (Tags a) where
70instance Binary a => Binary (Tags a) where
@@ -91,7 +90,8 @@ readTagsWith :: (Page a -> [String]) -- ^ Function extracting tags from a page
91 -> [Page a] -- ^ Pages
90 -> [Page a] -- ^ Pages
92 -> Tags a -- ^ Resulting tags
91 -> Tags a -- ^ Resulting tags
93readTagsWith f pages = Tags
92readTagsWith f pages = Tags
93+ { tagsMap = M.toList $
94− { tagsMap = foldl (M.unionWith (++)) M.empty (map readTagsWith' pages)
94+ foldl (M.unionWith (++)) M.empty (map readTagsWith' pages)
95 }
95 }
96 where
96 where
97 -- Create a tag map for one page
97 -- Create a tag map for one page
@@ -122,7 +122,7 @@ renderTags :: (String -> Identifier)
122renderTags makeUrl makeItem concatItems = proc (Tags tags) -> do
122renderTags makeUrl makeItem concatItems = proc (Tags tags) -> do
123 -- In tags' we create a list: [((tag, route), count)]
123 -- In tags' we create a list: [((tag, route), count)]
124 tags' <- mapCompiler ((id &&& (getRouteFor <<^ makeUrl)) *** arr length)
124 tags' <- mapCompiler ((id &&& (getRouteFor <<^ makeUrl)) *** arr length)
125− -< M.toList tags
125+ -< tags
126
126
127 let -- Absolute frequencies of the pages
127 let -- Absolute frequencies of the pages
128 freqs = map snd tags'
128 freqs = map snd tags'