on master help sign in
Implement interval-based preview
commit371c28cb1a7976740f104b0737b6b9c37c08b72f authorJasper Van der Jeugt <jaspervdj@gmail.com> dateMon 21 Feb 2011, 13:35 (16 years ago) parent9178295
1 file changed+36
src/Hakyll/Web/Preview/Interval.hs+36
src/Hakyll/Web/Preview/Interval.hsnew file+36
@@ -0,0 +1,36 @@
1+-- | Interval-based implementation of preview polling, for the platforms which
2+-- are not supported by inotify.
3+--
4+module Hakyll.Web.Preview.Interval
5+ ( previewPoll
6+ ) where
7+
8+import Control.Applicative ((<$>))
9+import Control.Concurrent (threadDelay)
10+import Control.Monad (when)
11+import System.Time (getClockTime)
12+import Data.Set (Set)
13+import qualified Data.Set as S
14+import System.Directory (getModificationTime)
15+
16+import Hakyll.Core.Configuration
17+import Hakyll.Core.Identifier
18+import Hakyll.Core.ResourceProvider
19+
20+-- | A preview thread that periodically recompiles the site.
21+--
22+previewPoll :: HakyllConfiguration -- ^ Configuration
23+ -> Set Resource -- ^ Resources to watch
24+ -> IO () -- ^ Action called when something changes
25+ -> IO () -- ^ Can block forever
26+previewPoll _ resources callback = do
27+ let files = map (toFilePath . unResource) $ S.toList resources
28+ time <- getClockTime
29+ loop files time
30+ where
31+ delay = 1000000
32+ loop files time = do
33+ threadDelay delay
34+ modified <- any (time <) <$> mapM getModificationTime files
35+ when modified callback
36+ loop files =<< getClockTime