@@ -11,7 +11,7 @@ module Text.Hakyll.HakyllAction
1111
1212import Control.Arrow
1313import Control.Category
14−import Control.Monad ((<=<), mplus, unless)
14+import Control.Monad ((<=<), unless)
1515import Control.Monad.Reader (liftIO)
1616import Prelude hiding ((.), id)
1717import System.IO (hPutStrLn, stderr)
@@ -24,7 +24,8 @@ data HakyllAction a b = HakyllAction
2424 { -- | Dependencies of the @HakyllAction@.
2525 actionDependencies :: [FilePath]
2626 , -- | URL pointing to the result of this @HakyllAction@.
27− actionUrl :: Maybe (Hakyll FilePath)
27+ actionUrl :: Either (Hakyll FilePath)
28+ (Hakyll FilePath -> Hakyll FilePath)
2829 , -- | The actual render function.
2930 actionFunction :: a -> Hakyll b
3031 }
@@ -45,7 +46,7 @@ createFileHakyllAction :: FilePath -- ^ File to operate on.
4546 -> HakyllAction () b -- ^ The resulting action.
4647createFileHakyllAction path action = HakyllAction
4748 { actionDependencies = [path]
48− , actionUrl = Just $ return path
49+ , actionUrl = Left $ return path
4950 , actionFunction = const action
5051 }
5152
@@ -60,8 +61,8 @@ runHakyllActionIfNeeded :: HakyllAction () () -- ^ Action to run.
6061 -> Hakyll () -- ^ Empty result.
6162runHakyllActionIfNeeded action = do
6263 url <- case actionUrl action of
63− (Just u) -> u
64− Nothing -> error "No url when checking dependencies."
64+ Left u -> u
65+ Right _ -> error "No url when checking dependencies."
6566 destination <- toDestination url
6667 valid <- isFileMoreRecent destination $ actionDependencies action
6768 unless valid $ do liftIO $ hPutStrLn stderr $ "Rendering " ++ destination
@@ -76,13 +77,17 @@ chain list = foldl1 (>>>) list
7677instance Category HakyllAction where
7778 id = HakyllAction
7879 { actionDependencies = []
79− , actionUrl = Nothing
80+ , actionUrl = Right id
8081 , actionFunction = return
8182 }
8283
8384 x . y = HakyllAction
8485 { actionDependencies = actionDependencies x ++ actionDependencies y
85− , actionUrl = actionUrl x `mplus` actionUrl y
86+ , actionUrl = case actionUrl x of
87+ Left ux -> Left ux
88+ Right fx -> case actionUrl y of
89+ Left uy -> Left (fx uy)
90+ Right fy -> Right (fx . fy)
8691 , actionFunction = actionFunction x <=< actionFunction y
8792 }
8893