From 7825f62fa2720cc6b4a94de127478af9759a6eb0 Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Sat, 5 Oct 2024 18:13:49 +0200 Subject: [PATCH] Run pandoc on text instead of file --- byg/src/DependencyGenerator.hs | 2 +- byg/src/Evaluation/FunctionIO.hs | 3 +-- byg/src/SiteGenerator.hs | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/byg/src/DependencyGenerator.hs b/byg/src/DependencyGenerator.hs index 82f860c..0bfb28e 100644 --- a/byg/src/DependencyGenerator.hs +++ b/byg/src/DependencyGenerator.hs @@ -262,5 +262,5 @@ copyFile' = runFunctionIO' CopyFile makeDir :: TokenableTo FilePath a => a -> DepGenM () 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 diff --git a/byg/src/Evaluation/FunctionIO.hs b/byg/src/Evaluation/FunctionIO.hs index 4a87c49..1b25e67 100644 --- a/byg/src/Evaluation/FunctionIO.hs +++ b/byg/src/Evaluation/FunctionIO.hs @@ -51,8 +51,7 @@ evalFunctionIO f x = case (f, x) of createDirectory s pure Empty - (RunPandoc, String (StringWrapper s)) -> do - contents <- T.readFile s + (RunPandoc, Text contents) -> do 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 diff --git a/byg/src/SiteGenerator.hs b/byg/src/SiteGenerator.hs index 02ca838..0fcb4d0 100644 --- a/byg/src/SiteGenerator.hs +++ b/byg/src/SiteGenerator.hs @@ -48,7 +48,7 @@ handleRecipeDir inputDir outputDir template indexName name = do mapDepGenM_ (\files -> convertImage files $ inject $ ResizeToWidth 800) (zipDepGenM imagePaths thumbnailImagePaths) - htmlBodyBase <- runPandoc $ joinPaths dir $ inject "ret.md" + htmlBodyBase <- runPandoc $ readTextFile $ joinPaths dir $ inject "ret.md" htmlBodyImages <- mapDepGenM makeImageHTML $ zipDepGenM thumbnailImageFilenames imageFilenames imagesHtml <- concatTexts htmlBodyImages htmlBody <- appendTexts htmlBodyBase imagesHtml @@ -69,7 +69,7 @@ generateSite = do dirPathsAreSubdirs <- mapDepGenM isDirectory dirPaths dirNames' <- filterDepGenM dirPathsAreSubdirs 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" makeDir aboutDir saveFile html $ joinPaths aboutDir indexName