@@ -1,9 +1,8 @@
11module Hakyll.Preview.Poll
2− ( previewPoll
2+ ( watchUpdates
33 ) where
44
55--------------------------------------------------------------------------------
6−import Control.Monad (void)
76import Filesystem.Path.CurrentOS (decodeString, encodeString)
87import System.Directory (getCurrentDirectory)
98import System.FilePath (makeRelative)
@@ -16,21 +15,21 @@ import Hakyll.Core.Configuration
1615
1716
1817--------------------------------------------------------------------------------
19−-- | A preview thread that recompiles the site when files change.
20−previewPoll :: Configuration -- ^ Configuration
21− -> IO [FilePath] -- ^ Updating action
22− -> IO () -- ^ Can block forever
23−previewPoll conf update = do
18+-- | A thread that watches for updates in a 'providerDirectory' and recompiles
19+-- a site as soon as any changes occur
20+watchUpdates :: Configuration -> IO () -> IO ()
21+watchUpdates conf update = do
2422 _ <- update
2523 manager <- startManagerConf (Debounce 0.1)
26− wDir <- getCurrentDirectory
27− watchTree manager path (predicate wDir) (\_ -> void update)
24+ workingDirectory <- getCurrentDirectory
25+ watchTree manager path (predicate workingDirectory) $ const update
2826 where
2927 path = decodeString $ providerDirectory conf
3028 predicate wDir evt
3129 | isRemove evt = False
3230 | otherwise = not $ shouldIgnoreFile conf (relativeEventPath wDir evt)
3331
32+
3433relativeEventPath :: FilePath -> Event -> FilePath
3534relativeEventPath b evt = makeRelative b $ encodeString $ evtPath evt
3635 where
@@ -38,6 +37,7 @@ relativeEventPath b evt = makeRelative b $ encodeString $ evtPath evt
3837 evtPath (Modified p _) = p
3938 evtPath (Removed p _) = p
4039
40+
4141isRemove :: Event -> Bool
4242isRemove (Removed _ _) = True
4343isRemove _ = False