2012-12-29 08:53:59 +00:00
|
|
|
module Hakyll.Preview.Poll
|
2013-03-31 11:47:47 +00:00
|
|
|
( watchUpdates
|
2011-02-21 12:35:20 +00:00
|
|
|
) where
|
|
|
|
|
2012-12-29 08:53:59 +00:00
|
|
|
--------------------------------------------------------------------------------
|
2013-03-30 14:28:23 +00:00
|
|
|
import Filesystem.Path.CurrentOS (decodeString, encodeString)
|
2013-03-30 16:38:31 +00:00
|
|
|
import System.Directory (getCurrentDirectory)
|
|
|
|
import System.FilePath (makeRelative)
|
2013-03-30 15:24:20 +00:00
|
|
|
import System.FSNotify (startManagerConf, watchTree,
|
|
|
|
Event(..), WatchConfig(..))
|
2012-12-29 08:53:59 +00:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Hakyll.Core.Configuration
|
2011-02-21 12:35:20 +00:00
|
|
|
|
|
|
|
|
2013-03-30 14:28:23 +00:00
|
|
|
|
2012-12-29 08:53:59 +00:00
|
|
|
--------------------------------------------------------------------------------
|
2013-03-31 11:47:47 +00:00
|
|
|
-- | 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
|
2013-03-30 16:07:16 +00:00
|
|
|
_ <- update
|
|
|
|
manager <- startManagerConf (Debounce 0.1)
|
2013-03-31 11:47:47 +00:00
|
|
|
workingDirectory <- getCurrentDirectory
|
|
|
|
watchTree manager path (predicate workingDirectory) $ const update
|
2011-02-21 12:35:20 +00:00
|
|
|
where
|
2013-03-30 14:28:23 +00:00
|
|
|
path = decodeString $ providerDirectory conf
|
2013-03-30 16:38:31 +00:00
|
|
|
predicate wDir evt
|
2013-03-30 14:28:23 +00:00
|
|
|
| isRemove evt = False
|
2013-03-30 16:38:31 +00:00
|
|
|
| otherwise = not $ shouldIgnoreFile conf (relativeEventPath wDir evt)
|
2013-03-30 14:28:23 +00:00
|
|
|
|
2013-03-31 11:47:47 +00:00
|
|
|
|
2013-03-30 16:38:31 +00:00
|
|
|
relativeEventPath :: FilePath -> Event -> FilePath
|
|
|
|
relativeEventPath b evt = makeRelative b $ encodeString $ evtPath evt
|
|
|
|
where
|
|
|
|
evtPath (Added p _) = p
|
|
|
|
evtPath (Modified p _) = p
|
|
|
|
evtPath (Removed p _) = p
|
2013-03-30 14:28:23 +00:00
|
|
|
|
2013-03-31 11:47:47 +00:00
|
|
|
|
2013-03-30 14:28:23 +00:00
|
|
|
isRemove :: Event -> Bool
|
|
|
|
isRemove (Removed _ _) = True
|
|
|
|
isRemove _ = False
|