diff options
-rw-r--r-- | src/Text/Hakyll.hs | 3 | ||||
-rw-r--r-- | src/Text/Hakyll/Hakyll.hs | 17 | ||||
-rw-r--r-- | src/Text/Hakyll/Render/Internal.hs | 9 |
3 files changed, 18 insertions, 11 deletions
diff --git a/src/Text/Hakyll.hs b/src/Text/Hakyll.hs index 2586c02..ae31fc3 100644 --- a/src/Text/Hakyll.hs +++ b/src/Text/Hakyll.hs @@ -15,8 +15,7 @@ import System.Directory (doesDirectoryExist, removeDirectoryRecursive) -- | Default hakyll configuration. defaultHakyllConfiguration :: HakyllConfiguration defaultHakyllConfiguration = HakyllConfiguration - { hakyllDestination = "_site" - , hakyllGlobalContext = M.empty + { additionalContext = M.empty } -- | Main function to run hakyll. diff --git a/src/Text/Hakyll/Hakyll.hs b/src/Text/Hakyll/Hakyll.hs index 3690914..c7f6d89 100644 --- a/src/Text/Hakyll/Hakyll.hs +++ b/src/Text/Hakyll/Hakyll.hs @@ -1,15 +1,24 @@ +-- | Module describing the Hakyll monad stack. module Text.Hakyll.Hakyll ( HakyllConfiguration (..) , Hakyll + , askHakyll ) where import Text.Hakyll.Context (Context) -import System.FilePath (FilePath) -import Control.Monad.Reader (ReaderT) +import Control.Monad.Reader (ReaderT, ask) +import Control.Monad (liftM) +-- | Hakyll global configuration type. data HakyllConfiguration = HakyllConfiguration - { hakyllDestination :: FilePath - , hakyllGlobalContext :: Context + { -- | An additional context to use when rendering. This additional context + -- is used globally. + additionalContext :: Context } +-- | Our custom monad stack. type Hakyll = ReaderT HakyllConfiguration IO + +-- | Simplified "ask" function for the Hakyll monad stack. +askHakyll :: (HakyllConfiguration -> a) -> Hakyll a +askHakyll = flip liftM ask diff --git a/src/Text/Hakyll/Render/Internal.hs b/src/Text/Hakyll/Render/Internal.hs index e296dd2..7e5fd37 100644 --- a/src/Text/Hakyll/Render/Internal.hs +++ b/src/Text/Hakyll/Render/Internal.hs @@ -11,8 +11,7 @@ module Text.Hakyll.Render.Internal import qualified Data.Map as M import Text.Hakyll.Context (Context, ContextManipulation) -import Control.Monad.Reader (ask, liftIO) -import Control.Monad (liftM) +import Control.Monad.Reader (liftIO) import Data.List (isPrefixOf, foldl') import Data.Char (isAlpha) import Data.Maybe (fromMaybe) @@ -20,7 +19,7 @@ import Control.Parallel.Strategies (rdeepseq, ($|)) import Text.Hakyll.Renderable import Text.Hakyll.Page import Text.Hakyll.File -import Text.Hakyll.Hakyll (Hakyll, hakyllGlobalContext) +import Text.Hakyll.Hakyll -- | Substitutes `$identifiers` in the given string by values from the given -- "Context". When a key is not found, it is left as it is. You can here @@ -84,9 +83,9 @@ pureRenderChainWith manipulation templates context = -- chains and such. writePage :: Page -> Hakyll () writePage page = do - globalContext <- liftM hakyllGlobalContext ask + additionalContext' <- askHakyll additionalContext let destination = toDestination url - context = (M.singleton "root" $ toRoot url) `M.union` globalContext + context = additionalContext' `M.union` (M.singleton "root" $ toRoot url) makeDirectories destination -- Substitute $root here, just before writing. liftIO $ writeFile destination $ finalSubstitute (getBody page) context |