@@ -12,6 +12,7 @@ module Hakyll.Core.Target.Internal
12import Control.Applicative (Applicative)
12import Control.Applicative (Applicative)
13import Control.Monad.Trans (MonadIO)
13import Control.Monad.Trans (MonadIO)
14import Control.Monad.Reader (ReaderT, runReaderT)
14import Control.Monad.Reader (ReaderT, runReaderT)
15+import Control.Monad.State (StateT, evalStateT)
16import Hakyll.Core.Identifier
17import Hakyll.Core.Identifier
17import Hakyll.Core.ResourceProvider
18import Hakyll.Core.ResourceProvider
@@ -30,11 +31,18 @@ data TargetEnvironment a = TargetEnvironment
30 , targetStore :: Store -- ^ Store for caching
31 , targetStore :: Store -- ^ Store for caching
34+-- | State for the target monad
36+data TargetState = TargetState
37+ { targetSnapshot :: Int -- ^ Snapshot ID
33-- | Monad for targets. In this monad, the user can compose targets and describe
40-- | Monad for targets. In this monad, the user can compose targets and describe
34-- how they should be created.
41-- how they should be created.
43+newtype TargetM a b = TargetM
36−newtype TargetM a b = TargetM {unTargetM :: ReaderT (TargetEnvironment a) IO b}
44+ { unTargetM :: ReaderT (TargetEnvironment a) (StateT TargetState IO) b
37− deriving (Monad, Functor, Applicative, MonadIO)
45+ } deriving (Monad, Functor, Applicative, MonadIO)
39-- | Simplification of the 'TargetM' type for concrete cases: the type of the
47-- | Simplification of the 'TargetM' type for concrete cases: the type of the
40-- returned item should equal the type of the dependencies.
48-- returned item should equal the type of the dependencies.
@@ -49,7 +57,8 @@ runTarget :: Target a
49 -> ResourceProvider
57 -> ResourceProvider
52−runTarget target id' lookup' provider store = runReaderT (unTargetM target) env
60+runTarget target id' lookup' provider store =
61+ evalStateT (runReaderT (unTargetM target) env) state
54 env = TargetEnvironment
63 env = TargetEnvironment
55 { targetIdentifier = id'
64 { targetIdentifier = id'
@@ -57,3 +66,6 @@ runTarget target id' lookup' provider store = runReaderT (unTargetM target) env
57 , targetResourceProvider = provider
66 , targetResourceProvider = provider
58 , targetStore = store
67 , targetStore = store