on master help sign in
Add a takeBody function
commit6b44cef123af6426a55838707586b6ac95f9db8b authorJasper Van der Jeugt <jaspervdj@gmail.com> dateThu 28 Oct 2010, 13:32 (16 years ago) parent1f169dd
3 files changed+13−7
src/Text/Hakyll/ContextManipulations.hs+6 src/Text/Hakyll/Internal/Template.hs+4−4 src/Text/Hakyll/Render.hs+3−3
src/Text/Hakyll/ContextManipulations.hs+6
@@ -9,6 +9,7 @@ module Text.Hakyll.ContextManipulations
99 , renderDateWithLocale
1010 , changeExtension
1111 , renderBody
12+ , takeBody
1213 ) where
1314
1415import Control.Monad (liftM)
@@ -115,3 +116,8 @@ changeExtension extension = changeValue "url" changeExtension'
115116renderBody :: (String -> String)
116117 -> HakyllAction Context Context
117118renderBody = 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
2121import Text.Hakyll.Pandoc
2222import Text.Hakyll.Internal.Cache
2323import Text.Hakyll.Page
24+import Text.Hakyll.ContextManipulations
2425import Text.Hakyll.Internal.Template.Template
2526import Text.Hakyll.Internal.Template.Hamlet
2627
@@ -56,10 +57,9 @@ readTemplate path = do
5657 where
5758 fileName = "templates" </> path
5859 readDefaultTemplate = do
59− page <- unContext <$>
60− runHakyllAction (readPageAction path >>> renderAction)
61− let body = fromMaybe (error $ "No body in template " ++ fileName)
62− (M.lookup "body" page)
60+ body <- runHakyllAction $ readPageAction path
61+ >>> renderAction
62+ >>> takeBody
6363 return $ fromString body
6464
6565 readHamletTemplate = fromHamletRT <$> readHamletRT path
src/Text/Hakyll/Render.hs+3−3
@@ -9,7 +9,7 @@ module Text.Hakyll.Render
99 , writePage
1010 ) where
1111
12−import Control.Arrow ((>>>))
12+import Control.Arrow ((>>>), arr)
1313import Control.Applicative ((<$>))
1414import Control.Monad.Reader (liftIO)
1515import System.Directory (copyFile)
@@ -67,8 +67,8 @@ renderAndConcat templatePaths renderables = HakyllAction
6767 renders = map (>>> render') renderables
6868
6969 actionFunction' _ = do
70− contexts <- mapM runHakyllAction renders
71− return $ concatMap (fromMaybe "" . M.lookup "body" . unContext) contexts
70+ contexts <- mapM (runHakyllAction . (>>> takeBody)) renders
71+ return $ concat contexts
7272
7373-- | Chain a render action for a page with a number of templates. This will
7474-- also write the result to the site destination. This is the preferred way