Run pandoc on text instead of file

This commit is contained in:
Niels G. W. Serup 2024-10-05 18:13:49 +02:00
parent 47420cbe41
commit 7825f62fa2
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
3 changed files with 4 additions and 5 deletions

View File

@ -262,5 +262,5 @@ copyFile' = runFunctionIO' CopyFile
makeDir :: TokenableTo FilePath a => a -> DepGenM () makeDir :: TokenableTo FilePath a => a -> DepGenM ()
makeDir a = runFunctionIO' MakeDir =<< toToken a makeDir a = runFunctionIO' MakeDir =<< toToken a
runPandoc :: TokenableTo FilePath a => a -> DepGenM' Text runPandoc :: TokenableTo Text a => a -> DepGenM' Text
runPandoc a = runFunctionIO RunPandoc =<< toToken a runPandoc a = runFunctionIO RunPandoc =<< toToken a

View File

@ -51,8 +51,7 @@ evalFunctionIO f x = case (f, x) of
createDirectory s createDirectory s
pure Empty pure Empty
(RunPandoc, String (StringWrapper s)) -> do (RunPandoc, Text contents) -> do
contents <- T.readFile s
html <- P.runIOorExplode (P.writeHtml5 P.def =<< P.readMarkdown (P.def { P.readerExtensions = P.extensionsFromList [ P.Ext_raw_html ] }) contents) html <- P.runIOorExplode (P.writeHtml5 P.def =<< P.readMarkdown (P.def { P.readerExtensions = P.extensionsFromList [ P.Ext_raw_html ] }) contents)
pure $ Text $ TL.toStrict $ B.renderHtml html pure $ Text $ TL.toStrict $ B.renderHtml html

View File

@ -48,7 +48,7 @@ handleRecipeDir inputDir outputDir template indexName name = do
mapDepGenM_ mapDepGenM_
(\files -> convertImage files $ inject $ ResizeToWidth 800) (\files -> convertImage files $ inject $ ResizeToWidth 800)
(zipDepGenM imagePaths thumbnailImagePaths) (zipDepGenM imagePaths thumbnailImagePaths)
htmlBodyBase <- runPandoc $ joinPaths dir $ inject "ret.md" htmlBodyBase <- runPandoc $ readTextFile $ joinPaths dir $ inject "ret.md"
htmlBodyImages <- mapDepGenM makeImageHTML $ zipDepGenM thumbnailImageFilenames imageFilenames htmlBodyImages <- mapDepGenM makeImageHTML $ zipDepGenM thumbnailImageFilenames imageFilenames
imagesHtml <- concatTexts htmlBodyImages imagesHtml <- concatTexts htmlBodyImages
htmlBody <- appendTexts htmlBodyBase imagesHtml htmlBody <- appendTexts htmlBodyBase imagesHtml
@ -69,7 +69,7 @@ generateSite = do
dirPathsAreSubdirs <- mapDepGenM isDirectory dirPaths dirPathsAreSubdirs <- mapDepGenM isDirectory dirPaths
dirNames' <- filterDepGenM dirPathsAreSubdirs dirNames dirNames' <- filterDepGenM dirPathsAreSubdirs dirNames
mapDepGenM_ (handleRecipeDir recipesDir outputRecipesDir template indexName) dirNames' mapDepGenM_ (handleRecipeDir recipesDir outputRecipesDir template indexName) dirNames'
html <- applyTemplate template $ runPandoc $ inject "om.md" html <- applyTemplate template $ runPandoc $ readTextFile $ inject "om.md"
aboutDir <- joinPaths outputDir $ inject "om" aboutDir <- joinPaths outputDir $ inject "om"
makeDir aboutDir makeDir aboutDir
saveFile html $ joinPaths aboutDir indexName saveFile html $ joinPaths aboutDir indexName