|
@@ -1,5 +1,6 @@
|
1
|
1
|
module Main where
|
2
|
2
|
|
|
3
|
+import Control.Concurrent (threadDelay)
|
3
|
4
|
import Control.Monad
|
4
|
5
|
import Data.Aeson
|
5
|
6
|
import qualified Data.Map as M
|
|
@@ -11,6 +12,7 @@ import Path.IO ( copyDirRecur )
|
11
|
12
|
import System.Console.ArgParser
|
12
|
13
|
import System.Directory
|
13
|
14
|
import System.FilePath
|
|
15
|
+import System.FSNotify
|
14
|
16
|
import Text.Pandoc
|
15
|
17
|
|
16
|
18
|
import Build ( buildRawPost
|
|
@@ -90,6 +92,22 @@ build dir drafts = do
|
90
|
92
|
_ -> putStrLn $ unlines $ map show renderErrors
|
91
|
93
|
_ -> putStrLn $ unlines $ map show parseErrors
|
92
|
94
|
|
|
95
|
+handleEvent :: FilePath -> Bool -> Event -> IO ()
|
|
96
|
+handleEvent dir drafts _event = do
|
|
97
|
+ putStrLn "Rebuilding"
|
|
98
|
+ build dir drafts
|
|
99
|
+
|
|
100
|
+watch :: FilePath -> Bool -> IO ()
|
|
101
|
+watch dir drafts = do
|
|
102
|
+ withManager $ \mgr -> do
|
|
103
|
+ putStrLn "Watching..."
|
|
104
|
+ watchTree
|
|
105
|
+ mgr
|
|
106
|
+ dir
|
|
107
|
+ (const True)
|
|
108
|
+ (handleEvent dir drafts)
|
|
109
|
+ forever $ threadDelay 1000000
|
|
110
|
+
|
93
|
111
|
new :: String -> IO ()
|
94
|
112
|
new name = do
|
95
|
113
|
path <- makeAbsolute name
|
|
@@ -108,6 +126,7 @@ new name = do
|
108
|
126
|
run :: Config -> IO ()
|
109
|
127
|
run config = case config of
|
110
|
128
|
(Build dir drafts) -> build dir drafts
|
|
129
|
+ (Watch dir drafts) -> watch dir drafts
|
111
|
130
|
(New name ) -> new name
|
112
|
131
|
|
113
|
132
|
main :: IO ()
|