summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-12-31 15:15:35 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-12-31 15:15:35 +0100
commite54834f4448f4bcc6fb55fb338ffcfd4390fd356 (patch)
tree6a3e0bb03ed73c82e11eb96caafb49bf6bd42af5 /src
parent8bb4ea5c83fb96842f85d2d167e96c4eae09d4ea (diff)
downloadhakyll-e54834f4448f4bcc6fb55fb338ffcfd4390fd356.tar.gz
Check modification only once
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Core/Compiler.hs3
-rw-r--r--src/Hakyll/Core/Compiler/Internal.hs21
-rw-r--r--src/Hakyll/Core/Run.hs10
3 files changed, 25 insertions, 9 deletions
diff --git a/src/Hakyll/Core/Compiler.hs b/src/Hakyll/Core/Compiler.hs
index 67724bd..fdc7d20 100644
--- a/src/Hakyll/Core/Compiler.hs
+++ b/src/Hakyll/Core/Compiler.hs
@@ -83,10 +83,9 @@ cached :: (Binary a)
-> Compiler () a
-> Compiler () a
cached name (Compiler d j) = Compiler d $ const $ CompilerM $ do
- provider <- compilerResourceProvider <$> ask
identifier <- compilerIdentifier <$> ask
store <- compilerStore <$> ask
- modified <- liftIO $ resourceModified provider identifier store
+ modified <- compilerResourceModified <$> ask
liftIO $ putStrLn $
show identifier ++ ": " ++ if modified then "MODIFIED" else "OK"
if modified
diff --git a/src/Hakyll/Core/Compiler/Internal.hs b/src/Hakyll/Core/Compiler/Internal.hs
index 4209bdc..a4dd695 100644
--- a/src/Hakyll/Core/Compiler/Internal.hs
+++ b/src/Hakyll/Core/Compiler/Internal.hs
@@ -37,11 +37,18 @@ type DependencyLookup = Identifier -> CompiledItem
-- | Environment in which a compiler runs
--
data CompilerEnvironment = CompilerEnvironment
- { compilerIdentifier :: Identifier -- ^ Target identifier
- , compilerResourceProvider :: ResourceProvider -- ^ Resource provider
- , compilerDependencyLookup :: DependencyLookup -- ^ Dependency lookup
- , compilerRoute :: Maybe FilePath -- ^ Site route
- , compilerStore :: Store -- ^ Compiler store
+ { -- | Target identifier
+ compilerIdentifier :: Identifier
+ , -- | Resource provider
+ compilerResourceProvider :: ResourceProvider
+ , -- | Dependency lookup
+ compilerDependencyLookup :: DependencyLookup
+ , -- | Site route
+ compilerRoute :: Maybe FilePath
+ , -- | Compiler store
+ compilerStore :: Store
+ , -- | Flag indicating if the underlying resource was modified
+ compilerResourceModified :: Bool
}
-- | The compiler monad
@@ -76,8 +83,9 @@ runCompilerJob :: Compiler () a -- ^ Compiler to run
-> DependencyLookup -- ^ Dependency lookup table
-> Maybe FilePath -- ^ Route
-> Store -- ^ Store
+ -> Bool -- ^ Was the resource modified?
-> IO a
-runCompilerJob compiler identifier provider lookup' route store =
+runCompilerJob compiler identifier provider lookup' route store modified =
runReaderT (unCompilerM $ compilerJob compiler ()) env
where
env = CompilerEnvironment
@@ -86,6 +94,7 @@ runCompilerJob compiler identifier provider lookup' route store =
, compilerDependencyLookup = lookup'
, compilerRoute = route
, compilerStore = store
+ , compilerResourceModified = modified
}
runCompilerDependencies :: Compiler () a
diff --git a/src/Hakyll/Core/Run.hs b/src/Hakyll/Core/Run.hs
index 636f9e4..1b45f38 100644
--- a/src/Hakyll/Core/Run.hs
+++ b/src/Hakyll/Core/Run.hs
@@ -67,8 +67,15 @@ hakyllWith rules provider store = do
where
addTarget route' map' (id', comp) = do
let url = runRoute route' id'
+
+ -- Check if the resource was modified
+ modified <- if resourceExists provider id'
+ then resourceModified provider id' store
+ else return False
+
+ -- Run the compiler
compiled <- runCompilerJob comp id' provider (dependencyLookup map')
- url store
+ url store modified
putStrLn $ "Generated target: " ++ show id'
case url of
@@ -79,6 +86,7 @@ hakyllWith rules provider store = do
makeDirectories path
write path compiled
+ putStrLn ""
return $ M.insert id' compiled map'
dependencyLookup map' id' = case M.lookup id' map' of