Check modification only once

This commit is contained in:
Jasper Van der Jeugt 2010-12-31 15:15:35 +01:00
parent 8bb4ea5c83
commit e54834f444
3 changed files with 25 additions and 9 deletions

View file

@ -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

View file

@ -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

View file

@ -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