A static site generator written in Haskell
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

12345678910111213141516171819202122232425262728293031323334353637383940
  1. module Post where
  2. import qualified Data.Text as T
  3. import System.FilePath
  4. import Text.Pandoc
  5. type RawPost = (FilePath, T.Text)
  6. type RichPost = (FilePath, Pandoc)
  7. parsePosts :: [RawPost] -> [(FilePath, Either PandocError Pandoc)]
  8. parsePosts = map (\(path, contents) -> (path, parsePost contents))
  9. parsePost :: T.Text -> Either PandocError Pandoc
  10. parsePost contents = runPure $ readMarkdown readerOptions contents
  11. renderPosts :: String -> [RichPost] -> [(FilePath, Either PandocError T.Text)]
  12. renderPosts layout =
  13. map (\(path, post) -> (path, renderPost layout (path, post)))
  14. renderPost :: String -> RichPost -> Either PandocError T.Text
  15. renderPost layout (path, post) =
  16. runPure $ writeHtml5String (writerOptions $ Just layout) post
  17. readerOptions :: ReaderOptions
  18. readerOptions =
  19. let extensions = extensionsFromList
  20. [ Ext_fenced_code_attributes
  21. , Ext_fenced_code_blocks
  22. , Ext_footnotes
  23. , Ext_link_attributes
  24. , Ext_yaml_metadata_block
  25. , Ext_simple_tables
  26. ]
  27. in def { readerExtensions = extensions }
  28. writerOptions :: Maybe String -> WriterOptions
  29. writerOptions layout = case layout of
  30. Just t -> def { writerTemplate = Just t }
  31. Nothing -> def