diff options
Diffstat (limited to 'src/Hakyll/Core')
-rw-r--r-- | src/Hakyll/Core/Compiler.hs | 28 | ||||
-rw-r--r-- | src/Hakyll/Core/Run.hs | 12 |
2 files changed, 34 insertions, 6 deletions
diff --git a/src/Hakyll/Core/Compiler.hs b/src/Hakyll/Core/Compiler.hs index 60c8ecb..8a87fef 100644 --- a/src/Hakyll/Core/Compiler.hs +++ b/src/Hakyll/Core/Compiler.hs @@ -7,6 +7,7 @@ module Hakyll.Core.Compiler , Compiler , runCompiler , require + , requireAll , compileFromString ) where @@ -20,10 +21,12 @@ import Data.Typeable (Typeable) import Data.Binary (Binary) import Hakyll.Core.Identifier +import Hakyll.Core.Identifier.Pattern import Hakyll.Core.Target import Hakyll.Core.Target.Internal import Hakyll.Core.CompiledItem import Hakyll.Core.Writable +import Hakyll.Core.ResourceProvider -- | A set of dependencies -- @@ -41,7 +44,8 @@ addDependency dependency = CompilerM $ modify $ addDependency' -- | Environment in which a compiler runs -- data CompilerEnvironment = CompilerEnvironment - { compilerIdentifier :: Identifier -- ^ Target identifier + { compilerIdentifier :: Identifier -- ^ Target identifier + , compilerResourceProvider :: ResourceProvider -- ^ Resource provider } -- | State carried along by a compiler @@ -63,12 +67,17 @@ type Compiler a = CompilerM (TargetM a) -- | Run a compiler, yielding the resulting target and it's dependencies -- -runCompiler :: Compiler a -> Identifier -> (TargetM a, Dependencies) -runCompiler compiler identifier = second compilerDependencies $ +runCompiler :: Compiler a -> Identifier -> ResourceProvider + -> (TargetM a, Dependencies) +runCompiler compiler identifier provider = second compilerDependencies $ runState (runReaderT (unCompilerM compiler) env) state where - env = CompilerEnvironment {compilerIdentifier = identifier} state = CompilerState S.empty + env = CompilerEnvironment + { compilerIdentifier = identifier + , compilerResourceProvider = provider + } + -- | Require another target. Using this function ensures automatic handling of -- dependencies @@ -82,6 +91,17 @@ require identifier = do lookup' <- targetDependencyLookup <$> ask return $ unCompiledItem $ lookup' identifier +-- | Require a number of targets. Using this function ensures automatic handling +-- of dependencies +-- +requireAll :: (Binary a, Typeable a, Writable a) + => Pattern + -> Compiler [a] +requireAll pattern = CompilerM $ do + provider <- compilerResourceProvider <$> ask + r <- unCompilerM $ mapM require $ matches pattern $ resourceList provider + return $ sequence r + -- | Construct a target from a string, this string being the content of the -- resource. -- diff --git a/src/Hakyll/Core/Run.hs b/src/Hakyll/Core/Run.hs index e2ff9f3..1a79aa9 100644 --- a/src/Hakyll/Core/Run.hs +++ b/src/Hakyll/Core/Run.hs @@ -8,14 +8,17 @@ import qualified Data.Map as M import Data.Monoid (mempty) import Data.Typeable (Typeable) import Data.Binary (Binary) +import System.FilePath ((</>)) import Hakyll.Core.Route +import Hakyll.Core.Util.File import Hakyll.Core.Compiler import Hakyll.Core.ResourceProvider import Hakyll.Core.ResourceProvider.FileResourceProvider import Hakyll.Core.Rules import Hakyll.Core.Target import Hakyll.Core.DirectedGraph +import Hakyll.Core.DirectedGraph.Dot import Hakyll.Core.DirectedGraph.DependencySolver import Hakyll.Core.Writable import Hakyll.Core.Store @@ -37,7 +40,7 @@ hakyllWith rules provider store = do -- Get all targets targets = flip map compilers $ \(id', compiler) -> - let (targ, deps) = runCompiler compiler id' + let (targ, deps) = runCompiler compiler id' provider in (id', targ, deps) -- Map mapping every identifier to it's target @@ -55,6 +58,9 @@ hakyllWith rules provider store = do -- Fetch the routes route' = rulesRoute ruleSet + putStrLn "Writing dependency graph to dependencies.dot..." + writeDot "dependencies.dot" show graph + -- Generate all the targets in order _ <- foldM (addTarget route') M.empty orderedTargets @@ -68,7 +74,9 @@ hakyllWith rules provider store = do Nothing -> return () Just r -> do putStrLn $ "Routing " ++ show id' ++ " to " ++ r - write r compiled + let path = "_site" </> r + makeDirectories path + write path compiled return $ M.insert id' compiled map' |