summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-29 16:22:08 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-29 16:22:08 +0100
commitfe33635a880bfb6f3d182f20aad5542b9f6152ce (patch)
tree0db3f07e0fa592926635203f674a8d61ab74239a /src
parent0e925e71e18d61f9b4eee715378946f47ad0e819 (diff)
downloadhakyll-fe33635a880bfb6f3d182f20aad5542b9f6152ce.tar.gz
Fix dependency issues for tags
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Core/Dependencies.hs6
-rw-r--r--src/Hakyll/Core/Rules.hs22
-rw-r--r--src/Hakyll/Web/Tags.hs17
3 files changed, 35 insertions, 10 deletions
diff --git a/src/Hakyll/Core/Dependencies.hs b/src/Hakyll/Core/Dependencies.hs
index e81b38f..7597e61 100644
--- a/src/Hakyll/Core/Dependencies.hs
+++ b/src/Hakyll/Core/Dependencies.hs
@@ -88,8 +88,10 @@ markOod id' = State.modify $ \s ->
dependenciesFor :: Identifier -> DependencyM [Identifier]
dependenciesFor id' = do
facts <- dependencyFacts <$> State.get
- let relevant = fromMaybe [] $ M.lookup id' facts
- return [i | IdentifierDependency i <- relevant]
+ return $ concatMap dependenciesFor' $ fromMaybe [] $ M.lookup id' facts
+ where
+ dependenciesFor' (IdentifierDependency i) = [i]
+ dependenciesFor' (PatternDependency _ is) = is
--------------------------------------------------------------------------------
diff --git a/src/Hakyll/Core/Rules.hs b/src/Hakyll/Core/Rules.hs
index fb6458b..a234306 100644
--- a/src/Hakyll/Core/Rules.hs
+++ b/src/Hakyll/Core/Rules.hs
@@ -22,6 +22,9 @@ module Hakyll.Core.Rules
, version
, compile
, route
+
+ -- * Advanced usage
+ , rulesExtraDependencies
) where
@@ -29,7 +32,7 @@ module Hakyll.Core.Rules
import Control.Applicative ((<$>))
import Control.Arrow (second)
import Control.Monad.Reader (ask, local)
-import Control.Monad.Writer (tell)
+import Control.Monad.Writer (censor, tell)
import Data.Monoid (mappend, mempty)
import qualified Data.Set as S
@@ -41,6 +44,7 @@ import Data.Typeable (Typeable)
--------------------------------------------------------------------------------
import Hakyll.Core.Compiler.Internal
+import Hakyll.Core.Dependencies
import Hakyll.Core.Identifier
import Hakyll.Core.Identifier.Pattern
import Hakyll.Core.Item
@@ -125,3 +129,19 @@ route route' = Rules $ do
version' <- rulesVersion <$> ask
unRules $ tellRoute $ matchRoute
(pattern `mappend` fromVersion version') route'
+
+
+--------------------------------------------------------------------------------
+-- | Advanced usage: add extra dependencies to compilers. Basically this is
+-- needed when you're doing unsafe tricky stuff in the rules monad, but you
+-- still want correct builds.
+rulesExtraDependencies :: [Dependency] -> Rules a -> Rules a
+rulesExtraDependencies deps = Rules . censor addDependencies . unRules
+ where
+ -- Adds the dependencies to the compilers in the ruleset
+ addDependencies ruleSet = ruleSet
+ { rulesCompilers =
+ [ (i, compilerTellDependencies deps >> c)
+ | (i, c) <- rulesCompilers ruleSet
+ ]
+ }
diff --git a/src/Hakyll/Web/Tags.hs b/src/Hakyll/Web/Tags.hs
index c5f2b1f..ae70568 100644
--- a/src/Hakyll/Web/Tags.hs
+++ b/src/Hakyll/Web/Tags.hs
@@ -75,6 +75,7 @@ import qualified Text.Blaze.Html5.Attributes as A
--------------------------------------------------------------------------------
import Hakyll.Core.Compiler
+import Hakyll.Core.Dependencies
import Hakyll.Core.Identifier
import Hakyll.Core.Identifier.Pattern
import Hakyll.Core.Item
@@ -88,8 +89,9 @@ import Hakyll.Web.Urls
--------------------------------------------------------------------------------
-- | Data about tags
data Tags = Tags
- { tagsMap :: [(String, [Identifier])]
- , tagsMakeId :: String -> Identifier
+ { tagsMap :: [(String, [Identifier])]
+ , tagsMakeId :: String -> Identifier
+ , tagsDependency :: Dependency
} deriving (Show)
@@ -117,7 +119,7 @@ buildTagsWith :: MonadMetadata m
buildTagsWith f pattern makeId = do
ids <- getMatches pattern
tagMap <- foldM addTags M.empty ids
- return $ Tags (M.toList tagMap) makeId
+ return $ Tags (M.toList tagMap) makeId (PatternDependency pattern ids)
where
-- Create a tag map for one page
addTags tagMap id' = do
@@ -142,7 +144,8 @@ tagsRules :: Tags -> (String -> Pattern -> Rules ()) -> Rules ()
tagsRules tags rules =
forM_ (tagsMap tags) $ \(tag, identifiers) ->
match (fromGlob $ toFilePath $ tagsMakeId tags tag) $
- rules tag $ fromList identifiers
+ rulesExtraDependencies [tagsDependency tags] $
+ rules tag $ fromList identifiers
--------------------------------------------------------------------------------
@@ -154,10 +157,10 @@ renderTags :: (String -> String -> Int -> Int -> Int -> String)
-> Tags
-- ^ Tag cloud renderer
-> Compiler String
-renderTags makeHtml concatHtml (Tags tags makeTagId) = do
+renderTags makeHtml concatHtml tags = do
-- In tags' we create a list: [((tag, route), count)]
- tags' <- forM tags $ \(tag, ids) -> do
- route' <- getRoute $ makeTagId tag
+ tags' <- forM (tagsMap tags) $ \(tag, ids) -> do
+ route' <- getRoute $ tagsMakeId tags tag
return ((tag, route'), length ids)
-- TODO: We actually need to tell a dependency here!