diff options
Diffstat (limited to 'src/Hakyll/Core')
-rw-r--r-- | src/Hakyll/Core/Compiler.hs | 13 | ||||
-rw-r--r-- | src/Hakyll/Core/Compiler/Internal.hs | 13 | ||||
-rw-r--r-- | src/Hakyll/Core/Run.hs | 5 |
3 files changed, 22 insertions, 9 deletions
diff --git a/src/Hakyll/Core/Compiler.hs b/src/Hakyll/Core/Compiler.hs index d0e219e..5678b0a 100644 --- a/src/Hakyll/Core/Compiler.hs +++ b/src/Hakyll/Core/Compiler.hs @@ -4,6 +4,7 @@ module Hakyll.Core.Compiler ( Compiler , getIdentifier + , getRoute , getResourceString , require , requireAll @@ -26,10 +27,18 @@ import Hakyll.Core.Writable import Hakyll.Core.ResourceProvider import Hakyll.Core.Compiler.Internal +-- | Get the identifier of the item that is currently being compiled +-- getIdentifier :: Compiler a Identifier -getIdentifier = fromJob $ const $ CompilerM $ - compilerIdentifier <$> ask +getIdentifier = fromJob $ const $ CompilerM $ compilerIdentifier <$> ask + +-- | Get the route we are using for this item +-- +getRoute :: Compiler a (Maybe FilePath) +getRoute = fromJob $ const $ CompilerM $ compilerRoute <$> ask +-- | Get the resource we are compiling as a string +-- getResourceString :: Compiler a String getResourceString = getIdentifier >>> getResourceString' where diff --git a/src/Hakyll/Core/Compiler/Internal.hs b/src/Hakyll/Core/Compiler/Internal.hs index fd37343..eee67ef 100644 --- a/src/Hakyll/Core/Compiler/Internal.hs +++ b/src/Hakyll/Core/Compiler/Internal.hs @@ -39,6 +39,7 @@ data CompilerEnvironment = CompilerEnvironment { compilerIdentifier :: Identifier -- ^ Target identifier , compilerResourceProvider :: ResourceProvider -- ^ Resource provider , compilerDependencyLookup :: DependencyLookup -- ^ Dependency lookup + , compilerRoute :: Maybe FilePath -- ^ Site route } -- | The compiler monad @@ -67,18 +68,20 @@ instance Arrow Compiler where -- | Run a compiler, yielding the resulting target and it's dependencies -- -runCompilerJob :: Compiler () a - -> Identifier - -> ResourceProvider - -> DependencyLookup +runCompilerJob :: Compiler () a -- ^ Compiler to run + -> Identifier -- ^ Target identifier + -> ResourceProvider -- ^ Resource provider + -> DependencyLookup -- ^ Dependency lookup table + -> Maybe FilePath -- ^ Route -> IO a -runCompilerJob compiler identifier provider lookup' = +runCompilerJob compiler identifier provider lookup' route = runReaderT (unCompilerM $ compilerJob compiler ()) env where env = CompilerEnvironment { compilerIdentifier = identifier , compilerResourceProvider = provider , compilerDependencyLookup = lookup' + , compilerRoute = route } runCompilerDependencies :: Compiler () a diff --git a/src/Hakyll/Core/Run.hs b/src/Hakyll/Core/Run.hs index fa88458..ccb731c 100644 --- a/src/Hakyll/Core/Run.hs +++ b/src/Hakyll/Core/Run.hs @@ -66,10 +66,11 @@ hakyllWith rules provider store = do putStrLn "DONE." where addTarget route' map' (id', comp) = do - compiled <- runCompilerJob comp id' provider (dependencyLookup map') + let url = runRoute route' id' + compiled <- runCompilerJob comp id' provider (dependencyLookup map') url putStrLn $ "Generated target: " ++ show id' - case runRoute route' id' of + case url of Nothing -> return () Just r -> do putStrLn $ "Routing " ++ show id' ++ " to " ++ r |