on master help sign in
Add a takeBody function
6b44cefJasper Van der Jeugt
src/Text/Hakyll/ContextManipulations.hs+6
@@ -9,6 +9,7 @@ module Text.Hakyll.ContextManipulations
9 , renderDateWithLocale
9 , renderDateWithLocale
10 , changeExtension
10 , changeExtension
11 , renderBody
11 , renderBody
12+ , takeBody
12 ) where
13 ) where
13
14
14import Control.Monad (liftM)
15import Control.Monad (liftM)
@@ -115,3 +116,8 @@ changeExtension extension = changeValue "url" changeExtension'
115renderBody :: (String -> String)
116renderBody :: (String -> String)
116 -> HakyllAction Context Context
117 -> HakyllAction Context Context
117renderBody = renderValue "body" "body"
118renderBody = renderValue "body" "body"
119+
120+-- | Get the resulting body text from a context
121+--
122+takeBody :: HakyllAction Context String
123+takeBody = arr $ fromMaybe "" . M.lookup "body" . unContext
src/Text/Hakyll/Internal/Template.hs+4−4
@@ -21,6 +21,7 @@ import Text.Hakyll.HakyllAction
21import Text.Hakyll.Pandoc
21import Text.Hakyll.Pandoc
22import Text.Hakyll.Internal.Cache
22import Text.Hakyll.Internal.Cache
23import Text.Hakyll.Page
23import Text.Hakyll.Page
24+import Text.Hakyll.ContextManipulations
24import Text.Hakyll.Internal.Template.Template
25import Text.Hakyll.Internal.Template.Template
25import Text.Hakyll.Internal.Template.Hamlet
26import Text.Hakyll.Internal.Template.Hamlet
26
27
@@ -56,10 +57,9 @@ readTemplate path = do
56 where
57 where
57 fileName = "templates" </> path
58 fileName = "templates" </> path
58 readDefaultTemplate = do
59 readDefaultTemplate = do
59− page <- unContext <$>
60− runHakyllAction (readPageAction path >>> renderAction)
60+ body <- runHakyllAction $ readPageAction path
61− let body = fromMaybe (error $ "No body in template " ++ fileName)
61+ >>> renderAction
62− (M.lookup "body" page)
62+ >>> takeBody
63 return $ fromString body
63 return $ fromString body
64
64
65 readHamletTemplate = fromHamletRT <$> readHamletRT path
65 readHamletTemplate = fromHamletRT <$> readHamletRT path
src/Text/Hakyll/Render.hs+3−3
@@ -9,7 +9,7 @@ module Text.Hakyll.Render
9 , writePage
9 , writePage
10 ) where
10 ) where
11
11
12−import Control.Arrow ((>>>))
12+import Control.Arrow ((>>>), arr)
13import Control.Applicative ((<$>))
13import Control.Applicative ((<$>))
14import Control.Monad.Reader (liftIO)
14import Control.Monad.Reader (liftIO)
15import System.Directory (copyFile)
15import System.Directory (copyFile)
@@ -67,8 +67,8 @@ renderAndConcat templatePaths renderables = HakyllAction
67 renders = map (>>> render') renderables
67 renders = map (>>> render') renderables
68
68
69 actionFunction' _ = do
69 actionFunction' _ = do
70− contexts <- mapM runHakyllAction renders
70+ contexts <- mapM (runHakyllAction . (>>> takeBody)) renders
71− return $ concatMap (fromMaybe "" . M.lookup "body" . unContext) contexts
71+ return $ concat contexts
72
72
73-- | Chain a render action for a page with a number of templates. This will
73-- | Chain a render action for a page with a number of templates. This will
74-- also write the result to the site destination. This is the preferred way
74-- also write the result to the site destination. This is the preferred way