Added pure renderAndConcat function.
This commit is contained in:
parent
ecd00b386e
commit
a26f84dab5
2 changed files with 18 additions and 9 deletions
|
@ -10,7 +10,7 @@ module Text.Hakyll.Render
|
|||
, css
|
||||
) where
|
||||
|
||||
import Control.Monad (unless, mapM, foldM)
|
||||
import Control.Monad (unless, mapM)
|
||||
|
||||
import System.Directory (copyFile)
|
||||
import System.IO
|
||||
|
@ -64,14 +64,10 @@ renderAndConcatWith :: Renderable a
|
|||
-> FilePath
|
||||
-> [a]
|
||||
-> IO String
|
||||
renderAndConcatWith manipulation templatePath renderables =
|
||||
foldM concatRender' [] renderables
|
||||
where
|
||||
concatRender' :: Renderable a => String -> a -> IO String
|
||||
concatRender' chunk renderable = do
|
||||
rendered <- renderWith manipulation templatePath renderable
|
||||
let body = getBody rendered
|
||||
return $ chunk ++ body
|
||||
renderAndConcatWith manipulation templatePath renderables = do
|
||||
template <- readFile templatePath
|
||||
contexts <- mapM toContext renderables
|
||||
return $ pureRenderAndConcatWith manipulation template 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
|
||||
|
|
|
@ -4,6 +4,7 @@ module Text.Hakyll.Render.Internal
|
|||
, regularSubstitute
|
||||
, finalSubstitute
|
||||
, pureRenderWith
|
||||
, pureRenderAndConcatWith
|
||||
, pureRenderChainWith
|
||||
, writePage
|
||||
) where
|
||||
|
@ -55,6 +56,18 @@ pureRenderWith manipulation template context =
|
|||
-- Force the body to be rendered.
|
||||
in ($|) id rnf (M.insert "body" body context)
|
||||
|
||||
-- | A pure renderAndConcat function.
|
||||
pureRenderAndConcatWith :: ContextManipulation
|
||||
-> String -- ^ Template to use.
|
||||
-> [Context] -- ^ Different renderables.
|
||||
-> String
|
||||
pureRenderAndConcatWith manipulation template contexts =
|
||||
foldl' renderAndConcat [] contexts
|
||||
where
|
||||
renderAndConcat chunk context =
|
||||
let rendered = pureRenderWith manipulation template context
|
||||
in chunk ++ fromMaybe "" (M.lookup "body" rendered)
|
||||
|
||||
-- | A pure renderChain function.
|
||||
pureRenderChainWith :: ContextManipulation
|
||||
-> [String]
|
||||
|
|
Loading…
Reference in a new issue