on master help sign in
Provide simple `renderActionWith` function
commit111828d282ea2a0a7d4a161960c4bc576bc89984 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateMon 4 Oct 2010, 17:14 (16 years ago) parent371bc03
1 file changed+13−7
src/Text/Hakyll/Pandoc.hs+13−7
src/Text/Hakyll/Pandoc.hs+13−7
@@ -2,11 +2,12 @@
22--
33module Text.Hakyll.Pandoc
44 ( renderAction
5+ , renderActionWith
56 ) where
67
78import Data.Maybe (fromMaybe)
89import qualified Data.Map as M
9−import Control.Arrow (second)
10+import Control.Arrow (second, (>>>), arr)
1011
1112import Text.Pandoc
1213
@@ -42,11 +43,16 @@ getRenderFunction fileType = do
4243--
4344renderAction :: HakyllAction [PageSection] Context
4445renderAction = createHakyllAction $ \sections -> do
45− let triples = map unPageSection sections
46− path = fromMaybe "unknown" $ lookup "path"
46+ let path = fromMaybe "unknown" $ lookup "path"
4747 $ map (\(x, y, _) -> (x, y))
48− $ triples
48+ $ map unPageSection sections
4949 render' <- getRenderFunction $ getFileType path
50− let pairs = map (\(k, v, r) -> second (if r then render' else id) (k, v))
51− triples
52− return $ Context $ M.fromList pairs
50+ runHakyllAction $ arr (const sections) >>> renderActionWith render'
51+
52+-- | An action to render pages, offering just a little more flexibility
53+--
54+renderActionWith :: (String -> String) -> HakyllAction [PageSection] Context
55+renderActionWith render' = createHakyllAction $ \sections -> return $
56+ Context $ M.fromList $ map (renderTriple . unPageSection) sections
57+ where
58+ renderTriple (k, v, r) = second (if r then render' else id) (k, v)