@@ -1,20 +1,17 @@
11-- | This is the module which binds it all together
22--
33{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4−module Hakyll.Core.Run where
4+module Hakyll.Core.Run
5+ ( run
6+ ) where
57
68import Prelude hiding (reverse)
79import Control.Applicative
810import Control.Monad.Reader
911import Control.Monad.State
10−import Control.Monad.Trans
1112import Control.Arrow ((&&&))
12−import Control.Monad (foldM, forM_, forM, filterM)
13−import Data.Map (Map)
1413import qualified Data.Map as M
1514import Data.Monoid (mempty, mappend)
16−import Data.Typeable (Typeable)
17−import Data.Binary (Binary)
1815import System.FilePath ((</>))
1916import Data.Set (Set)
2017import qualified Data.Set as S
@@ -32,45 +29,49 @@ import Hakyll.Core.DirectedGraph.Dot
3229import Hakyll.Core.DirectedGraph.DependencySolver
3330import Hakyll.Core.Writable
3431import Hakyll.Core.Store
35−import Hakyll.Core.CompiledItem
32+import Hakyll.Core.Configuration
3633
37−hakyll :: Rules -> IO ()
38−hakyll rules = do
39− store <- makeStore "_store"
34+-- | Run all rules needed
35+--
36+run :: HakyllConfiguration -> Rules -> IO ()
37+run configuration rules = do
38+ store <- makeStore $ storeDirectory configuration
4039 provider <- fileResourceProvider
4140 let ruleSet = runRules rules provider
4241 compilers = rulesCompilers ruleSet
4342
4443 -- Extract the reader/state
45− reader = unHakyll $ addNewCompilers [] compilers
44+ reader = unRuntime $ addNewCompilers [] compilers
4645 state' = runReaderT reader $ env ruleSet provider store
4746
4847 evalStateT state' state
4948 where
50− env ruleSet provider store = HakyllEnvironment
51− { hakyllRoute = rulesRoute ruleSet
49+ env ruleSet provider store = RuntimeEnvironment
50+ { hakyllConfiguration = configuration
51+ , hakyllRoute = rulesRoute ruleSet
5252 , hakyllResourceProvider = provider
5353 , hakyllStore = store
5454 }
5555
56− state = HakyllState
56+ state = RuntimeState
5757 { hakyllModified = S.empty
5858 , hakyllGraph = mempty
5959 }
6060
61−data HakyllEnvironment = HakyllEnvironment
62− { hakyllRoute :: Route
61+data RuntimeEnvironment = RuntimeEnvironment
62+ { hakyllConfiguration :: HakyllConfiguration
63+ , hakyllRoute :: Route
6364 , hakyllResourceProvider :: ResourceProvider
6465 , hakyllStore :: Store
6566 }
6667
67−data HakyllState = HakyllState
68+data RuntimeState = RuntimeState
6869 { hakyllModified :: Set Identifier
6970 , hakyllGraph :: DirectedGraph Identifier
7071 }
7172
72−newtype Hakyll a = Hakyll
73− { unHakyll :: ReaderT HakyllEnvironment (StateT HakyllState IO) a
73+newtype Runtime a = Runtime
74+ { unRuntime :: ReaderT RuntimeEnvironment (StateT RuntimeState IO) a
7475 } deriving (Functor, Applicative, Monad)
7576
7677-- | Return a set of modified identifiers
@@ -89,8 +90,8 @@ addNewCompilers :: [(Identifier, Compiler () CompileRule)]
8990 -- ^ Remaining compilers yet to be run
9091 -> [(Identifier, Compiler () CompileRule)]
9192 -- ^ Compilers to add
92− -> Hakyll ()
93−addNewCompilers oldCompilers newCompilers = Hakyll $ do
93+ -> Runtime ()
94+addNewCompilers oldCompilers newCompilers = Runtime $ do
9495 -- Get some information
9596 provider <- hakyllResourceProvider <$> ask
9697 store <- hakyllStore <$> ask
@@ -140,7 +141,7 @@ addNewCompilers oldCompilers newCompilers = Hakyll $ do
140141 modify $ updateState modified' completeGraph
141142
142143 -- Now run the ordered list of compilers
143− unHakyll $ runCompilers orderedCompilers
144+ unRuntime $ runCompilers orderedCompilers
144145 where
145146 -- Add the modified information for the new compilers
146147 updateState modified' graph state = state
@@ -150,10 +151,10 @@ addNewCompilers oldCompilers newCompilers = Hakyll $ do
150151
151152runCompilers :: [(Identifier, Compiler () CompileRule)]
152153 -- ^ Ordered list of compilers
153− -> Hakyll ()
154+ -> Runtime ()
154155 -- ^ No result
155156runCompilers [] = return ()
156−runCompilers ((id', compiler) : compilers) = Hakyll $ do
157+runCompilers ((id', compiler) : compilers) = Runtime $ do
157158 -- Obtain information
158159 route' <- hakyllRoute <$> ask
159160 provider <- hakyllResourceProvider <$> ask
@@ -175,18 +176,20 @@ runCompilers ((id', compiler) : compilers) = Hakyll $ do
175176 CompileRule compiled -> do
176177 case url of
177178 Nothing -> return ()
178− Just r -> liftIO $ do
179− putStrLn $ "Routing " ++ show id' ++ " to " ++ r
180− let path = "_site" </> r
181− makeDirectories path
182− write path compiled
179+ Just r -> do
180+ liftIO $ putStrLn $ "Routing " ++ show id' ++ " to " ++ r
181+ destination <-
182+ destinationDirectory . hakyllConfiguration <$> ask
183+ let path = destination </> r
184+ liftIO $ makeDirectories path
185+ liftIO $ write path compiled
183186
184187 liftIO $ putStrLn ""
185188
186189 -- Continue for the remaining compilers
187− unHakyll $ runCompilers compilers
190+ unRuntime $ runCompilers compilers
188191
189192 -- Metacompiler, slightly more complicated
190193 MetaCompileRule newCompilers ->
191194 -- Actually I was just kidding, it's not hard at all
192− unHakyll $ addNewCompilers compilers newCompilers
195+ unRuntime $ addNewCompilers compilers newCompilers