@@ -39,7 +39,6 @@ module Text.Hakyll.Tags
3939import qualified Data.Map as M
4040import Data.List (intercalate)
4141import Data.Maybe (fromMaybe, maybeToList)
42−import Control.Monad (foldM)
4342import Control.Arrow (second, (>>>))
4443import Control.Applicative ((<$>))
4544import System.FilePath
@@ -84,12 +83,20 @@ readMap getTagsFunction identifier paths = HakyllAction
8483 return assocMap'
8584 return $ M.map (map createPage) assocMap
8685
87− readTagMap' = foldM addPaths M.empty paths
88− addPaths current path = do
86+ -- TODO: preserve order
87+ readTagMap' :: Hakyll (M.Map String [FilePath])
88+ readTagMap' = do
89+ pairs' <- concat <$> mapM pairs paths
90+ return $ M.fromListWith (flip (++)) pairs'
91+
92+ -- | Read a page, and return an association list where every tag is
93+ -- associated with some paths. Of course, this will always be just one
94+ -- @FilePath@ here.
95+ pairs :: FilePath -> Hakyll [(String, [FilePath])]
96+ pairs path = do
8997 context <- runHakyllAction $ createPage path
9098 let tags = getTagsFunction context
91− addPaths' = flip (M.insertWith (++)) [path]
92− return $ foldr addPaths' current tags
99+ return $ map (\tag -> (tag, [path])) tags
93100
94101-- | Read a @TagMap@, using the @tags@ metadata field.
95102readTagMap :: String -- ^ Unique identifier for the map.