diff options
-rw-r--r-- | src/Text/Hakyll/ContextManipulations.hs | 6 | ||||
-rw-r--r-- | src/Text/Hakyll/Internal/Template.hs | 8 | ||||
-rw-r--r-- | src/Text/Hakyll/Render.hs | 6 |
3 files changed, 13 insertions, 7 deletions
diff --git a/src/Text/Hakyll/ContextManipulations.hs b/src/Text/Hakyll/ContextManipulations.hs index 2ececc6..46ee5ed 100644 --- a/src/Text/Hakyll/ContextManipulations.hs +++ b/src/Text/Hakyll/ContextManipulations.hs @@ -9,6 +9,7 @@ module Text.Hakyll.ContextManipulations , renderDateWithLocale , changeExtension , renderBody + , takeBody ) where import Control.Monad (liftM) @@ -115,3 +116,8 @@ changeExtension extension = changeValue "url" changeExtension' renderBody :: (String -> String) -> HakyllAction Context Context renderBody = renderValue "body" "body" + +-- | Get the resulting body text from a context +-- +takeBody :: HakyllAction Context String +takeBody = arr $ fromMaybe "" . M.lookup "body" . unContext diff --git a/src/Text/Hakyll/Internal/Template.hs b/src/Text/Hakyll/Internal/Template.hs index 59235cc..cd6a3bd 100644 --- a/src/Text/Hakyll/Internal/Template.hs +++ b/src/Text/Hakyll/Internal/Template.hs @@ -21,6 +21,7 @@ import Text.Hakyll.HakyllAction import Text.Hakyll.Pandoc import Text.Hakyll.Internal.Cache import Text.Hakyll.Page +import Text.Hakyll.ContextManipulations import Text.Hakyll.Internal.Template.Template import Text.Hakyll.Internal.Template.Hamlet @@ -56,10 +57,9 @@ readTemplate path = do where fileName = "templates" </> path readDefaultTemplate = do - page <- unContext <$> - runHakyllAction (readPageAction path >>> renderAction) - let body = fromMaybe (error $ "No body in template " ++ fileName) - (M.lookup "body" page) + body <- runHakyllAction $ readPageAction path + >>> renderAction + >>> takeBody return $ fromString body readHamletTemplate = fromHamletRT <$> readHamletRT path diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs index d054f63..16962bb 100644 --- a/src/Text/Hakyll/Render.hs +++ b/src/Text/Hakyll/Render.hs @@ -9,7 +9,7 @@ module Text.Hakyll.Render , writePage ) where -import Control.Arrow ((>>>)) +import Control.Arrow ((>>>), arr) import Control.Applicative ((<$>)) import Control.Monad.Reader (liftIO) import System.Directory (copyFile) @@ -67,8 +67,8 @@ renderAndConcat templatePaths renderables = HakyllAction renders = map (>>> render') renderables actionFunction' _ = do - contexts <- mapM runHakyllAction renders - return $ concatMap (fromMaybe "" . M.lookup "body" . unContext) contexts + contexts <- mapM (runHakyllAction . (>>> takeBody)) renders + return $ concat contexts -- | Chain a render action for a page with a number of templates. This will -- also write the result to the site destination. This is the preferred way |