on master help sign in
Fix dependency issues for tags
commitfe33635a880bfb6f3d182f20aad5542b9f6152ce authorJasper Van der Jeugt <m@jaspervdj.be> dateThu 29 Nov 2012, 16:22 (14 years ago) parent0e925e7
3 files changed+35−10
src/Hakyll/Core/Dependencies.hs+4−2 src/Hakyll/Core/Rules.hs+21−1 src/Hakyll/Web/Tags.hs+10−7
src/Hakyll/Core/Dependencies.hs+4−2
@@ -88,8 +88,10 @@ markOod id' = State.modify $ \s ->
8888dependenciesFor :: Identifier -> DependencyM [Identifier]
8989dependenciesFor id' = do
9090 facts <- dependencyFacts <$> State.get
91− let relevant = fromMaybe [] $ M.lookup id' facts
92− return [i | IdentifierDependency i <- relevant]
91+ return $ concatMap dependenciesFor' $ fromMaybe [] $ M.lookup id' facts
92+ where
93+ dependenciesFor' (IdentifierDependency i) = [i]
94+ dependenciesFor' (PatternDependency _ is) = is
9395
9496
9597--------------------------------------------------------------------------------
src/Hakyll/Core/Rules.hs+21−1
@@ -22,6 +22,9 @@ module Hakyll.Core.Rules
2222 , version
2323 , compile
2424 , route
25+
26+ -- * Advanced usage
27+ , rulesExtraDependencies
2528 ) where
2629
2730
@@ -29,7 +32,7 @@ module Hakyll.Core.Rules
2932import Control.Applicative ((<$>))
3033import Control.Arrow (second)
3134import Control.Monad.Reader (ask, local)
32−import Control.Monad.Writer (tell)
35+import Control.Monad.Writer (censor, tell)
3336import Data.Monoid (mappend, mempty)
3437import qualified Data.Set as S
3538
@@ -41,6 +44,7 @@ import Data.Typeable (Typeable)
4144
4245--------------------------------------------------------------------------------
4346import Hakyll.Core.Compiler.Internal
47+import Hakyll.Core.Dependencies
4448import Hakyll.Core.Identifier
4549import Hakyll.Core.Identifier.Pattern
4650import Hakyll.Core.Item
@@ -125,3 +129,19 @@ route route' = Rules $ do
125129 version' <- rulesVersion <$> ask
126130 unRules $ tellRoute $ matchRoute
127131 (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
7575
7676--------------------------------------------------------------------------------
7777import Hakyll.Core.Compiler
78+import Hakyll.Core.Dependencies
7879import Hakyll.Core.Identifier
7980import Hakyll.Core.Identifier.Pattern
8081import Hakyll.Core.Item
@@ -88,8 +89,9 @@ import Hakyll.Web.Urls
8889--------------------------------------------------------------------------------
8990-- | Data about tags
9091data Tags = Tags
91− { tagsMap :: [(String, [Identifier])]
92− , tagsMakeId :: String -> Identifier
92+ { tagsMap :: [(String, [Identifier])]
93+ , tagsMakeId :: String -> Identifier
94+ , tagsDependency :: Dependency
9395 } deriving (Show)
9496
9597
@@ -117,7 +119,7 @@ buildTagsWith :: MonadMetadata m
117119buildTagsWith f pattern makeId = do
118120 ids <- getMatches pattern
119121 tagMap <- foldM addTags M.empty ids
120− return $ Tags (M.toList tagMap) makeId
122+ return $ Tags (M.toList tagMap) makeId (PatternDependency pattern ids)
121123 where
122124 -- Create a tag map for one page
123125 addTags tagMap id' = do
@@ -142,7 +144,8 @@ tagsRules :: Tags -> (String -> Pattern -> Rules ()) -> Rules ()
142144tagsRules tags rules =
143145 forM_ (tagsMap tags) $ \(tag, identifiers) ->
144146 match (fromGlob $ toFilePath $ tagsMakeId tags tag) $
145− rules tag $ fromList identifiers
147+ rulesExtraDependencies [tagsDependency tags] $
148+ rules tag $ fromList identifiers
146149
147150
148151--------------------------------------------------------------------------------
@@ -154,10 +157,10 @@ renderTags :: (String -> String -> Int -> Int -> Int -> String)
154157 -> Tags
155158 -- ^ Tag cloud renderer
156159 -> Compiler String
157−renderTags makeHtml concatHtml (Tags tags makeTagId) = do
160+renderTags makeHtml concatHtml tags = do
158161 -- In tags' we create a list: [((tag, route), count)]
159− tags' <- forM tags $ \(tag, ids) -> do
160− route' <- getRoute $ makeTagId tag
162+ tags' <- forM (tagsMap tags) $ \(tag, ids) -> do
163+ route' <- getRoute $ tagsMakeId tags tag
161164 return ((tag, route'), length ids)
162165
163166 -- TODO: We actually need to tell a dependency here!