summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-05-28 10:43:27 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-05-28 10:43:27 +0200
commit01a8ab20d6ee5595da12601754931994865f09e6 (patch)
tree292a7f1cc5743d6ae744cde509d14763be56688d /src/Hakyll
parent73c93cc908300dbe5fbc25a20771fd1139c6e9b4 (diff)
parent6ab59438123d00b02b5a04235102df7af2926cd4 (diff)
downloadhakyll-01a8ab20d6ee5595da12601754931994865f09e6.tar.gz
Merge branch 'master' into type-safe-identifiers
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Web/Preview/Poll.hs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Hakyll/Web/Preview/Poll.hs b/src/Hakyll/Web/Preview/Poll.hs
new file mode 100644
index 0000000..83ec54a
--- /dev/null
+++ b/src/Hakyll/Web/Preview/Poll.hs
@@ -0,0 +1,34 @@
+-- | Interval-based implementation of preview polling
+--
+module Hakyll.Web.Preview.Poll
+ ( previewPoll
+ ) where
+
+import Control.Applicative ((<$>))
+import Control.Concurrent (threadDelay)
+import Control.Monad (filterM)
+import System.Time (getClockTime)
+import System.Directory (getModificationTime, doesFileExist)
+
+import Hakyll.Core.Configuration
+
+-- | A preview thread that periodically recompiles the site.
+--
+previewPoll :: HakyllConfiguration -- ^ Configuration
+ -> IO [FilePath] -- ^ Updating action
+ -> IO () -- ^ Can block forever
+previewPoll _ update = do
+ time <- getClockTime
+ loop time =<< update
+ where
+ delay = 1000000
+ loop time files = do
+ threadDelay delay
+ files' <- filterM doesFileExist files
+ filesTime <- case files' of
+ [] -> return time
+ _ -> maximum <$> mapM getModificationTime files'
+
+ if filesTime > time || files' /= files
+ then loop filesTime =<< update
+ else loop time files'