on master help sign in
Fixed error causing post lists to be reversed.

This error was caused when rendering post lists produced by readTagMap. I also gave some shorter implementations for functions in Text.Hakyll.HakyllAction.

commit0be1f8afbf02ee86b382697a02aa918fa8efa044 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSat 27 Mar 2010, 16:40 (17 years ago) parent509f919
2 files changed+16−11
src/Text/Hakyll/HakyllAction.hs+4−6 src/Text/Hakyll/Tags.hs+12−5
src/Text/Hakyll/HakyllAction.hs+4−6
@@ -82,16 +82,14 @@ instance Category HakyllAction where
8282
8383 x . y = HakyllAction
8484 { actionDependencies = actionDependencies x ++ actionDependencies y
85− , actionUrl = actionUrl y `mplus` actionUrl x
85+ , actionUrl = actionUrl x `mplus` actionUrl y
8686 , actionFunction = actionFunction x <=< actionFunction y
8787 }
8888
8989instance Arrow HakyllAction where
9090 arr f = id { actionFunction = return . f }
9191
92− first x = HakyllAction
93− { actionDependencies = actionDependencies x
94− , actionUrl = actionUrl x
95− , actionFunction = \(y, z) -> do y' <- actionFunction x y
96− return (y', z)
92+ first x = x
93+ { actionFunction = \(y, z) -> do y' <- actionFunction x y
94+ return (y', z)
9795 }
src/Text/Hakyll/Tags.hs+12−5
@@ -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.