on master help sign in
Provide simple `renderActionWith` function
111828dJasper Van der Jeugt
src/Text/Hakyll/Pandoc.hs+13−7
@@ -2,11 +2,12 @@
2--
2--
3module Text.Hakyll.Pandoc
3module Text.Hakyll.Pandoc
4 ( renderAction
4 ( renderAction
5+ , renderActionWith
5 ) where
6 ) where
6
7
7import Data.Maybe (fromMaybe)
8import Data.Maybe (fromMaybe)
8import qualified Data.Map as M
9import qualified Data.Map as M
9−import Control.Arrow (second)
10+import Control.Arrow (second, (>>>), arr)
10
11
11import Text.Pandoc
12import Text.Pandoc
12
13
@@ -42,11 +43,16 @@ getRenderFunction fileType = do
42--
43--
43renderAction :: HakyllAction [PageSection] Context
44renderAction :: HakyllAction [PageSection] Context
44renderAction = createHakyllAction $ \sections -> do
45renderAction = createHakyllAction $ \sections -> do
45− let triples = map unPageSection sections
46− path = fromMaybe "unknown" $ lookup "path"
46+ let path = fromMaybe "unknown" $ lookup "path"
47 $ map (\(x, y, _) -> (x, y))
47 $ map (\(x, y, _) -> (x, y))
48− $ triples
48+ $ map unPageSection sections
49 render' <- getRenderFunction $ getFileType path
49 render' <- getRenderFunction $ getFileType path
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
50− let pairs = map (\(k, v, r) -> second (if r then render' else id) (k, v))
58+ renderTriple (k, v, r) = second (if r then render' else id) (k, v)
51− triples
52− return $ Context $ M.fromList pairs