diff options
Diffstat (limited to 'src/Zettel/Render.hs')
-rw-r--r-- | src/Zettel/Render.hs | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/Zettel/Render.hs b/src/Zettel/Render.hs index b63e0d2..0a052f1 100644 --- a/src/Zettel/Render.hs +++ b/src/Zettel/Render.hs @@ -17,6 +17,7 @@ import Text.Pandoc.Scripting (noEngine) import Text.Pandoc.Templates (WithDefaultPartials (..), compileTemplate) import Text.Pandoc.Walk (query) import Text.Pandoc.Writers (writeMarkdown) +import System.FilePath ((</>), (<.>)) import Zettel.Types zettelIdToLink :: ZettelId -> Inline @@ -45,8 +46,8 @@ checkCitation :: Inline -> MB checkCitation Cite {} = MB True checkCitation _ = MB False -renderZettel :: ZettelId -> Zettel -> IO Text -renderZettel _ zettel = do +renderZettel :: FilePath -> Maybe FilePath -> ZettelId -> Zettel -> IO Text +renderZettel csl bib _ zettel = do templateFile <- getDataFileName "data/markdown.template" template <- decodeUtf8 <$> readFileBS templateFile Right templ <- runIOorExplode . runWithDefaultPartials $ compileTemplate "" template @@ -58,13 +59,13 @@ renderZettel _ zettel = do } ) runIOorExplode $ - if unMB $ query checkCitation zettel.zettelBody + if unMB (query checkCitation zettel.zettelBody) && isJust bib then let pandoc = - setMeta "csl" ("/Users/ymherklotz/Dropbox/zk/assets/ieee.csl" :: FilePath) $ + setMeta "csl" (csl :: FilePath) $ setMeta "bibliography" - (["/Users/ymherklotz/bibliography/references.bib"] :: [FilePath]) + ([fromMaybe "references.bib" bib] :: [FilePath]) zettel.zettelBody in applyFilters noEngine @@ -84,11 +85,14 @@ renderZettel _ zettel = do >>= writeMarkdown writeOpts else writeMarkdown writeOpts zettel.zettelBody -renderZettelFile :: FilePath -> ZettelId -> Zettel -> IO () -renderZettelFile dir ident zettel = do - t <- renderZettel ident zettel - writeFileText (dir <> "/" <> toString (unZettelId ident <> ".md")) t +renderZettelFile :: Bool -> FilePath -> Maybe FilePath -> FilePath -> ZettelId -> Zettel -> IO () +renderZettelFile v csl bib dir ident zettel = do + when v . putStrLn $ "Writing " <> path + t <- renderZettel csl bib ident zettel + writeFileText path t + where + path = dir </> toString (unZettelId ident) <.> "md" -renderZettelGraphFile :: FilePath -> ZettelGraph -> IO () -renderZettelGraphFile fp zg = - forM_ (Map.assocs (unZettelGraph zg)) $ uncurry (renderZettelFile fp) +renderZettelGraphFile :: Bool -> FilePath -> Maybe FilePath -> FilePath -> ZettelGraph -> IO () +renderZettelGraphFile v csl bib fp zg = + forM_ (Map.assocs (unZettelGraph zg)) $ uncurry (renderZettelFile v csl bib fp) |