From 371c28cb1a7976740f104b0737b6b9c37c08b72f Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 21 Feb 2011 13:35:20 +0100 Subject: Implement interval-based preview --- src/Hakyll/Web/Preview/Interval.hs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/Hakyll/Web/Preview/Interval.hs (limited to 'src/Hakyll') diff --git a/src/Hakyll/Web/Preview/Interval.hs b/src/Hakyll/Web/Preview/Interval.hs new file mode 100644 index 0000000..5ab90e5 --- /dev/null +++ b/src/Hakyll/Web/Preview/Interval.hs @@ -0,0 +1,36 @@ +-- | Interval-based implementation of preview polling, for the platforms which +-- are not supported by inotify. +-- +module Hakyll.Web.Preview.Interval + ( previewPoll + ) where + +import Control.Applicative ((<$>)) +import Control.Concurrent (threadDelay) +import Control.Monad (when) +import System.Time (getClockTime) +import Data.Set (Set) +import qualified Data.Set as S +import System.Directory (getModificationTime) + +import Hakyll.Core.Configuration +import Hakyll.Core.Identifier +import Hakyll.Core.ResourceProvider + +-- | A preview thread that periodically recompiles the site. +-- +previewPoll :: HakyllConfiguration -- ^ Configuration + -> Set Resource -- ^ Resources to watch + -> IO () -- ^ Action called when something changes + -> IO () -- ^ Can block forever +previewPoll _ resources callback = do + let files = map (toFilePath . unResource) $ S.toList resources + time <- getClockTime + loop files time + where + delay = 1000000 + loop files time = do + threadDelay delay + modified <- any (time <) <$> mapM getModificationTime files + when modified callback + loop files =<< getClockTime -- cgit v1.2.3