diff options
| author | Simonas Kazlauskas <git@kazlauskas.me> | 2013-03-31 14:47:47 +0300 |
|---|---|---|
| committer | Simonas Kazlauskas <git@kazlauskas.me> | 2013-03-31 14:47:47 +0300 |
| commit | 259190e30bb9136aef5b06546d47306edc2ad3ee (patch) | |
| tree | 2c97896584e2404ae5d9238e9b7fdea2701ee812 /src/Hakyll/Preview | |
| parent | bcc0ef828ec6f0abd8f397e6c04335e2c37256c9 (diff) | |
| download | hakyll-259190e30bb9136aef5b06546d47306edc2ad3ee.tar.gz | |
Refine code
This patch includes several smaller changes, namely:
1. We don't use result of `update` function and likely never will, so
don't bother generating it.
2. Rename watch function to better reflect what it does.
3. Never exit preview server in case of failed update.
Diffstat (limited to 'src/Hakyll/Preview')
| -rw-r--r-- | src/Hakyll/Preview/Poll.hs | 18 |
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 |
