module Post where import qualified Data.Text as T import System.FilePath import Text.Pandoc type RawPost = (FilePath, T.Text) type RichPost = (FilePath, Pandoc) parsePosts :: [RawPost] -> [(FilePath, Either PandocError Pandoc)] parsePosts = map (\(path, contents) -> (path, parsePost contents)) parsePost :: T.Text -> Either PandocError Pandoc parsePost contents = runPure $ readMarkdown readerOptions contents renderPosts :: String -> [RichPost] -> [(FilePath, Either PandocError T.Text)] renderPosts layout = map (\(path, post) -> (path, renderPost layout (path, post))) renderPost :: String -> RichPost -> Either PandocError T.Text renderPost layout (path, post) = runPure $ writeHtml5String (writerOptions $ Just layout) post readerOptions :: ReaderOptions readerOptions = let extensions = extensionsFromList [ Ext_fenced_code_attributes , Ext_fenced_code_blocks , Ext_footnotes , Ext_link_attributes , Ext_yaml_metadata_block , Ext_simple_tables ] in def { readerExtensions = extensions } writerOptions :: Maybe String -> WriterOptions writerOptions layout = case layout of Just t -> def { writerTemplate = Just t } Nothing -> def