public
Created

Monitor a directory to rebuild pandoc files automatically.

  • Download Gist
monitor.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
module Main where
 
import Filesystem (getWorkingDirectory)
import Filesystem.Path (extensions)
import System.FSNotify
import System.Exit
import System.Environment
import System.Cmd
import Control.Concurrent
import Control.Monad
import Data.String (fromString)
 
main = do
cwd <- getWorkingDirectory
args <- getArgs
when (null args) $ do
putStrLn "Please give at least one filename (with no extension, .pandoc is assumed)"
exitFailure
let files = map (\f -> (fromString $ f ++ ".pandoc", f)) args
putStrLn "Watching current directory, press RETURN to exit."
withManager $ \man -> do
_ <- forkIO $ do
watchTree man cwd (const True) $ \fp -> do
case fp of
Removed _ _ -> return ()
Added file _ -> maybeCompile file files
Modified file _ -> maybeCompile file files
_ <- getLine
exitSuccess
 
maybeCompile file files = case lookup file files of
Just f -> do
let command = "pandoc " ++ f ++ ".pandoc -N --smart --webtex -c buttondown.css -o " ++ f ++ ".html"
system command
return ()
Nothing -> return ()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.