on master help sign in
Fix dependency issues for tags
fe33635Jasper Van der Jeugt
src/Hakyll/Core/Dependencies.hs+4−2
@@ -88,8 +88,10 @@ markOod id' = State.modify $ \s ->
88dependenciesFor :: Identifier -> DependencyM [Identifier]
88dependenciesFor :: Identifier -> DependencyM [Identifier]
89dependenciesFor id' = do
89dependenciesFor id' = do
90 facts <- dependencyFacts <$> State.get
90 facts <- dependencyFacts <$> State.get
91− let relevant = fromMaybe [] $ M.lookup id' facts
91+ return $ concatMap dependenciesFor' $ fromMaybe [] $ M.lookup id' facts
92+ where
92− return [i | IdentifierDependency i <- relevant]
93+ dependenciesFor' (IdentifierDependency i) = [i]
94+ dependenciesFor' (PatternDependency _ is) = is
93
95
94
96
95--------------------------------------------------------------------------------
97--------------------------------------------------------------------------------
src/Hakyll/Core/Rules.hs+21−1
@@ -22,6 +22,9 @@ module Hakyll.Core.Rules
22 , version
22 , version
23 , compile
23 , compile
24 , route
24 , route
25+
26+ -- * Advanced usage
27+ , rulesExtraDependencies
25 ) where
28 ) where
26
29
27
30
@@ -29,7 +32,7 @@ module Hakyll.Core.Rules
29import Control.Applicative ((<$>))
32import Control.Applicative ((<$>))
30import Control.Arrow (second)
33import Control.Arrow (second)
31import Control.Monad.Reader (ask, local)
34import Control.Monad.Reader (ask, local)
32−import Control.Monad.Writer (tell)
35+import Control.Monad.Writer (censor, tell)
33import Data.Monoid (mappend, mempty)
36import Data.Monoid (mappend, mempty)
34import qualified Data.Set as S
37import qualified Data.Set as S
35
38
@@ -41,6 +44,7 @@ import Data.Typeable (Typeable)
41
44
42--------------------------------------------------------------------------------
45--------------------------------------------------------------------------------
43import Hakyll.Core.Compiler.Internal
46import Hakyll.Core.Compiler.Internal
47+import Hakyll.Core.Dependencies
44import Hakyll.Core.Identifier
48import Hakyll.Core.Identifier
45import Hakyll.Core.Identifier.Pattern
49import Hakyll.Core.Identifier.Pattern
46import Hakyll.Core.Item
50import Hakyll.Core.Item
@@ -125,3 +129,19 @@ route route' = Rules $ do
125 version' <- rulesVersion <$> ask
129 version' <- rulesVersion <$> ask
126 unRules $ tellRoute $ matchRoute
130 unRules $ tellRoute $ matchRoute
127 (pattern `mappend` fromVersion version') route'
131 (pattern `mappend` fromVersion version') route'
132+
133+
134+--------------------------------------------------------------------------------
135+-- | Advanced usage: add extra dependencies to compilers. Basically this is
136+-- needed when you're doing unsafe tricky stuff in the rules monad, but you
137+-- still want correct builds.
138+rulesExtraDependencies :: [Dependency] -> Rules a -> Rules a
139+rulesExtraDependencies deps = Rules . censor addDependencies . unRules
140+ where
141+ -- Adds the dependencies to the compilers in the ruleset
142+ addDependencies ruleSet = ruleSet
143+ { rulesCompilers =
144+ [ (i, compilerTellDependencies deps >> c)
145+ | (i, c) <- rulesCompilers ruleSet
146+ ]
147+ }
src/Hakyll/Web/Tags.hs+10−7
@@ -75,6 +75,7 @@ import qualified Text.Blaze.Html5.Attributes as A
75
75
76--------------------------------------------------------------------------------
76--------------------------------------------------------------------------------
77import Hakyll.Core.Compiler
77import Hakyll.Core.Compiler
78+import Hakyll.Core.Dependencies
78import Hakyll.Core.Identifier
79import Hakyll.Core.Identifier
79import Hakyll.Core.Identifier.Pattern
80import Hakyll.Core.Identifier.Pattern
80import Hakyll.Core.Item
81import Hakyll.Core.Item
@@ -88,8 +89,9 @@ import Hakyll.Web.Urls
88--------------------------------------------------------------------------------
89--------------------------------------------------------------------------------
89-- | Data about tags
90-- | Data about tags
90data Tags = Tags
91data Tags = Tags
91− { tagsMap :: [(String, [Identifier])]
92+ { tagsMap :: [(String, [Identifier])]
92− , tagsMakeId :: String -> Identifier
93+ , tagsMakeId :: String -> Identifier
94+ , tagsDependency :: Dependency
93 } deriving (Show)
95 } deriving (Show)
94
96
95
97
@@ -117,7 +119,7 @@ buildTagsWith :: MonadMetadata m
117buildTagsWith f pattern makeId = do
119buildTagsWith f pattern makeId = do
118 ids <- getMatches pattern
120 ids <- getMatches pattern
119 tagMap <- foldM addTags M.empty ids
121 tagMap <- foldM addTags M.empty ids
120− return $ Tags (M.toList tagMap) makeId
122+ return $ Tags (M.toList tagMap) makeId (PatternDependency pattern ids)
121 where
123 where
122 -- Create a tag map for one page
124 -- Create a tag map for one page
123 addTags tagMap id' = do
125 addTags tagMap id' = do
@@ -142,7 +144,8 @@ tagsRules :: Tags -> (String -> Pattern -> Rules ()) -> Rules ()
142tagsRules tags rules =
144tagsRules tags rules =
143 forM_ (tagsMap tags) $ \(tag, identifiers) ->
145 forM_ (tagsMap tags) $ \(tag, identifiers) ->
144 match (fromGlob $ toFilePath $ tagsMakeId tags tag) $
146 match (fromGlob $ toFilePath $ tagsMakeId tags tag) $
147+ rulesExtraDependencies [tagsDependency tags] $
145− rules tag $ fromList identifiers
148+ rules tag $ fromList identifiers
146
149
147
150
148--------------------------------------------------------------------------------
151--------------------------------------------------------------------------------
@@ -154,10 +157,10 @@ renderTags :: (String -> String -> Int -> Int -> Int -> String)
154 -> Tags
157 -> Tags
155 -- ^ Tag cloud renderer
158 -- ^ Tag cloud renderer
156 -> Compiler String
159 -> Compiler String
157−renderTags makeHtml concatHtml (Tags tags makeTagId) = do
160+renderTags makeHtml concatHtml tags = do
158 -- In tags' we create a list: [((tag, route), count)]
161 -- In tags' we create a list: [((tag, route), count)]
159− tags' <- forM tags $ \(tag, ids) -> do
162+ tags' <- forM (tagsMap tags) $ \(tag, ids) -> do
160− route' <- getRoute $ makeTagId tag
163+ route' <- getRoute $ tagsMakeId tags tag
161 return ((tag, route'), length ids)
164 return ((tag, route'), length ids)
162
165
163 -- TODO: We actually need to tell a dependency here!
166 -- TODO: We actually need to tell a dependency here!