summaryrefslogtreecommitdiff
path: root/src/Hakyll/Preview
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/Preview')
-rw-r--r--src/Hakyll/Preview/Poll.hs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/Hakyll/Preview/Poll.hs b/src/Hakyll/Preview/Poll.hs
index 9f7a505..65021db 100644
--- a/src/Hakyll/Preview/Poll.hs
+++ b/src/Hakyll/Preview/Poll.hs
@@ -1,9 +1,8 @@
module Hakyll.Preview.Poll
- ( previewPoll
+ ( watchUpdates
) where
--------------------------------------------------------------------------------
-import Control.Monad (void)
import Filesystem.Path.CurrentOS (decodeString, encodeString)
import System.Directory (getCurrentDirectory)
import System.FilePath (makeRelative)
@@ -16,21 +15,21 @@ import Hakyll.Core.Configuration
--------------------------------------------------------------------------------
--- | A preview thread that recompiles the site when files change.
-previewPoll :: Configuration -- ^ Configuration
- -> IO [FilePath] -- ^ Updating action
- -> IO () -- ^ Can block forever
-previewPoll conf update = do
+-- | A thread that watches for updates in a 'providerDirectory' and recompiles
+-- a site as soon as any changes occur
+watchUpdates :: Configuration -> IO () -> IO ()
+watchUpdates conf update = do
_ <- update
manager <- startManagerConf (Debounce 0.1)
- wDir <- getCurrentDirectory
- watchTree manager path (predicate wDir) (\_ -> void update)
+ workingDirectory <- getCurrentDirectory
+ watchTree manager path (predicate workingDirectory) $ const update
where
path = decodeString $ providerDirectory conf
predicate wDir evt
| isRemove evt = False
| otherwise = not $ shouldIgnoreFile conf (relativeEventPath wDir evt)
+
relativeEventPath :: FilePath -> Event -> FilePath
relativeEventPath b evt = makeRelative b $ encodeString $ evtPath evt
where
@@ -38,6 +37,7 @@ relativeEventPath b evt = makeRelative b $ encodeString $ evtPath evt
evtPath (Modified p _) = p
evtPath (Removed p _) = p
+
isRemove :: Event -> Bool
isRemove (Removed _ _) = True
isRemove _ = False