@@ -6,7 +6,8 @@
66{-# LANGUAGE MultiParamTypeClasses #-}
77module Hakyll.Core.Compiler.Internal
88 ( -- * Types
9− CompilerRead (..)
9+ Snapshot
10+ , CompilerRead (..)
1011 , CompilerWrite (..)
1112 , CompilerResult (..)
1213 , Compiler (..)
@@ -50,6 +51,12 @@ import Hakyll.Core.Routes
5051import Hakyll.Core.Store
5152
5253
54+--------------------------------------------------------------------------------
55+-- | Whilst compiling an item, it possible to save multiple snapshots of it, and
56+-- not just the final result.
57+type Snapshot = String
58+
59+
5360--------------------------------------------------------------------------------
5461-- | Environment in which a compiler runs
5562data CompilerRead = CompilerRead
@@ -86,9 +93,10 @@ instance Monoid CompilerWrite where
8693
8794--------------------------------------------------------------------------------
8895data CompilerResult a where
89− CompilerDone :: a -> CompilerWrite -> CompilerResult a
90− CompilerError :: [String] -> CompilerResult a
91− CompilerRequire :: Identifier -> Compiler a -> CompilerResult a
96+ CompilerDone :: a -> CompilerWrite -> CompilerResult a
97+ CompilerSnapshot :: Snapshot -> Compiler a -> CompilerResult a
98+ CompilerError :: [String] -> CompilerResult a
99+ CompilerRequire :: (Identifier, Snapshot) -> Compiler a -> CompilerResult a
92100
93101
94102--------------------------------------------------------------------------------
@@ -104,9 +112,10 @@ instance Functor Compiler where
104112 fmap f (Compiler c) = Compiler $ \r -> do
105113 res <- c r
106114 return $ case res of
107− CompilerDone x w -> CompilerDone (f x) w
108− CompilerError e -> CompilerError e
109− CompilerRequire i c' -> CompilerRequire i (fmap f c')
115+ CompilerDone x w -> CompilerDone (f x) w
116+ CompilerSnapshot s c' -> CompilerSnapshot s (fmap f c')
117+ CompilerError e -> CompilerError e
118+ CompilerRequire i c' -> CompilerRequire i (fmap f c')
110119 {-# INLINE fmap #-}
111120
112121
@@ -121,14 +130,16 @@ instance Monad Compiler where
121130 CompilerDone x w -> do
122131 res' <- unCompiler (f x) r
123132 return $ case res' of
124− CompilerDone y w' -> CompilerDone y (w `mappend` w')
125− CompilerError e -> CompilerError e
126− CompilerRequire i c' -> CompilerRequire i $ do
133+ CompilerDone y w' -> CompilerDone y (w `mappend` w')
134+ CompilerSnapshot s c' -> CompilerSnapshot s c'
135+ CompilerError e -> CompilerError e
136+ CompilerRequire i c' -> CompilerRequire i $ do
127137 compilerTell w -- Save dependencies!
128138 c'
129139
130− CompilerError e -> return $ CompilerError e
131− CompilerRequire i c' -> return $ CompilerRequire i $ c' >>= f
140+ CompilerSnapshot s c' -> return $ CompilerSnapshot s (c' >>= f)
141+ CompilerError e -> return $ CompilerError e
142+ CompilerRequire i c' -> return $ CompilerRequire i (c' >>= f)
132143 {-# INLINE (>>=) #-}
133144
134145 fail = compilerThrow . return
@@ -198,9 +209,10 @@ compilerCatch :: Compiler a -> ([String] -> Compiler a) -> Compiler a
198209compilerCatch (Compiler x) f = Compiler $ \r -> do
199210 res <- x r
200211 case res of
201− CompilerDone res' w -> return (CompilerDone res' w)
202− CompilerError e -> unCompiler (f e) r
203− CompilerRequire i c -> return (CompilerRequire i (compilerCatch c f))
212+ CompilerDone res' w -> return (CompilerDone res' w)
213+ CompilerSnapshot s c -> return (CompilerSnapshot s (compilerCatch c f))
214+ CompilerError e -> unCompiler (f e) r
215+ CompilerRequire i c -> return (CompilerRequire i (compilerCatch c f))
204216{-# INLINE compilerCatch #-}
205217
206218