@@ -7,7 +7,7 @@ module Text.Hakyll.Pandoc
77
88import Data.Maybe (fromMaybe)
99import qualified Data.Map as M
10−import Control.Arrow (second, (>>>), arr)
10+import Control.Arrow (second, (>>>), arr, (&&&))
1111
1212import Text.Pandoc
1313
@@ -19,15 +19,15 @@ import Text.Hakyll.Context
1919
2020-- | Get a render function for a given extension.
2121--
22−getRenderFunction :: FileType -> Hakyll (String -> String)
23−getRenderFunction Html = return id
24−getRenderFunction Text = return id
25−getRenderFunction UnknownFileType = return id
26−getRenderFunction fileType = do
27− parserState <- askHakyll pandocParserState
28− writerOptions <- askHakyll pandocWriterOptions
29− return $ writeHtmlString writerOptions
30− . readFunction fileType (readOptions parserState fileType)
22+getRenderFunction :: HakyllAction FileType (String -> String)
23+getRenderFunction = createHakyllAction $ \fileType -> case fileType of
24+ Html -> return id
25+ Text -> return id
26+ UnknownFileType -> return id
27+ _ -> do parserState <- askHakyll pandocParserState
28+ writerOptions <- askHakyll pandocWriterOptions
29+ return $ writeHtmlString writerOptions
30+ . readFunction fileType (readOptions parserState fileType)
3131 where
3232 readFunction ReStructuredText = readRST
3333 readFunction LaTeX = readLaTeX
@@ -42,17 +42,16 @@ getRenderFunction fileType = do
4242-- | An action that renders the list of page sections to a context using pandoc
4343--
4444renderAction :: HakyllAction [PageSection] Context
45−renderAction = createHakyllAction $ \sections -> do
46− let path = fromMaybe "unknown" $ lookup "path"
47− $ map (\(x, y, _) -> (x, y))
48− $ map unPageSection sections
49− render' <- getRenderFunction $ getFileType path
50− runHakyllAction $ arr (const sections) >>> renderActionWith render'
45+renderAction = (arr id &&& (getFileType' >>> getRenderFunction))
46+ >>> renderActionWith
47+ where
48+ getFileType' = arr $ getFileType . fromMaybe "unknown" . lookup "path"
49+ . map (\(x, y, _) -> (x, y)) . map unPageSection
5150
5251-- | An action to render pages, offering just a little more flexibility
5352--
54−renderActionWith :: (String -> String) -> HakyllAction [PageSection] Context
55−renderActionWith render' = createHakyllAction $ \sections -> return $
56− Context $ M.fromList $ map (renderTriple . unPageSection) sections
53+renderActionWith :: HakyllAction ([PageSection], String -> String) Context
54+renderActionWith = createHakyllAction $ \(sections, render') -> return $
55+ Context $ M.fromList $ map (renderTriple render' . unPageSection) sections
5756 where
58− renderTriple (k, v, r) = second (if r then render' else id) (k, v)
57+ renderTriple render' (k, v, r) = second (if r then render' else id) (k, v)