@@ -1,9 +1,8 @@
1module Hakyll.Preview.Poll
1module Hakyll.Preview.Poll
2− ( previewPoll
2+ ( watchUpdates
5--------------------------------------------------------------------------------
5--------------------------------------------------------------------------------
6−import Control.Monad (void)
7import Filesystem.Path.CurrentOS (decodeString, encodeString)
6import Filesystem.Path.CurrentOS (decodeString, encodeString)
8import System.Directory (getCurrentDirectory)
7import System.Directory (getCurrentDirectory)
9import System.FilePath (makeRelative)
8import System.FilePath (makeRelative)
@@ -16,21 +15,21 @@ import Hakyll.Core.Configuration
18--------------------------------------------------------------------------------
17--------------------------------------------------------------------------------
19−-- | A preview thread that recompiles the site when files change.
18+-- | A thread that watches for updates in a 'providerDirectory' and recompiles
20−previewPoll :: Configuration -- ^ Configuration
19+-- a site as soon as any changes occur
21− -> IO [FilePath] -- ^ Updating action
20+watchUpdates :: Configuration -> IO () -> IO ()
22− -> IO () -- ^ Can block forever
23−previewPoll conf update = do
21+watchUpdates conf update = do
24 _ <- update
22 _ <- update
25 manager <- startManagerConf (Debounce 0.1)
23 manager <- startManagerConf (Debounce 0.1)
26− wDir <- getCurrentDirectory
24+ workingDirectory <- getCurrentDirectory
27− watchTree manager path (predicate wDir) (\_ -> void update)
25+ watchTree manager path (predicate workingDirectory) $ const update
29 path = decodeString $ providerDirectory conf
27 path = decodeString $ providerDirectory conf
30 predicate wDir evt
28 predicate wDir evt
31 | isRemove evt = False
29 | isRemove evt = False
32 | otherwise = not $ shouldIgnoreFile conf (relativeEventPath wDir evt)
30 | otherwise = not $ shouldIgnoreFile conf (relativeEventPath wDir evt)
34relativeEventPath :: FilePath -> Event -> FilePath
33relativeEventPath :: FilePath -> Event -> FilePath
35relativeEventPath b evt = makeRelative b $ encodeString $ evtPath evt
34relativeEventPath b evt = makeRelative b $ encodeString $ evtPath evt
@@ -38,6 +37,7 @@ relativeEventPath b evt = makeRelative b $ encodeString $ evtPath evt
38 evtPath (Modified p _) = p
37 evtPath (Modified p _) = p
39 evtPath (Removed p _) = p
38 evtPath (Removed p _) = p
41isRemove :: Event -> Bool
41isRemove :: Event -> Bool
42isRemove (Removed _ _) = True
42isRemove (Removed _ _) = True
43isRemove _ = False
43isRemove _ = False