summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-02-12 12:01:23 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-02-12 12:01:23 +0100
commit6611e86ac5db5790b271f0b3e41376a0affdbb80 (patch)
tree5b2f5cc7d58a3fd7b41e8ee57a167407a6f86be4 /src/Text/Hakyll
parent732fdc9894fe8002c91b309ba8aeafc99e9f5be3 (diff)
downloadhakyll-6611e86ac5db5790b271f0b3e41376a0affdbb80.tar.gz
Added autocompile mode to replace preview mode.
Diffstat (limited to 'src/Text/Hakyll')
-rw-r--r--src/Text/Hakyll/File.hs24
-rw-r--r--src/Text/Hakyll/Hakyll.hs2
-rw-r--r--src/Text/Hakyll/Internal/Cache.hs2
-rw-r--r--src/Text/Hakyll/Render.hs2
4 files changed, 21 insertions, 9 deletions
diff --git a/src/Text/Hakyll/File.hs b/src/Text/Hakyll/File.hs
index 311bd57..421a29c 100644
--- a/src/Text/Hakyll/File.hs
+++ b/src/Text/Hakyll/File.hs
@@ -10,12 +10,14 @@ module Text.Hakyll.File
, getRecursiveContents
, sortByBaseName
, havingExtension
- , isMoreRecent
, directory
+ , isMoreRecent
+ , isFileMoreRecent
) where
import System.Directory
import System.FilePath
+import System.Time (ClockTime)
import Control.Monad
import Data.List (isPrefixOf, sortBy)
import Control.Monad.Reader (liftIO)
@@ -144,14 +146,22 @@ havingExtension extension = filter ((==) extension . takeExtension)
directory :: (FilePath -> Hakyll ()) -> FilePath -> Hakyll ()
directory action dir = getRecursiveContents dir >>= mapM_ action
--- | Check if a file is newer then a number of given files.
-isMoreRecent :: FilePath -- ^ The cached file.
+-- | Check if a timestamp is newer then a number of given files.
+isMoreRecent :: ClockTime -- ^ The time to check.
-> [FilePath] -- ^ Dependencies of the cached file.
-> Hakyll Bool
-isMoreRecent file depends = do
+isMoreRecent _ [] = return True
+isMoreRecent timeStamp depends = do
+ dependsModified <- liftIO $ mapM getModificationTime depends
+ return (timeStamp >= maximum dependsModified)
+
+-- | Check if a file is newer then a number of given files.
+isFileMoreRecent :: FilePath -- ^ The cached file.
+ -> [FilePath] -- ^ Dependencies of the cached file.
+ -> Hakyll Bool
+isFileMoreRecent file depends = do
exists <- liftIO $ doesFileExist file
if not exists
then return False
- else do dependsModified <- liftIO $ mapM getModificationTime depends
- fileModified <- liftIO $ getModificationTime file
- return (fileModified >= maximum dependsModified)
+ else do timeStamp <- liftIO $ getModificationTime file
+ isMoreRecent timeStamp depends
diff --git a/src/Text/Hakyll/Hakyll.hs b/src/Text/Hakyll/Hakyll.hs
index 08cb7ea..4f36c88 100644
--- a/src/Text/Hakyll/Hakyll.hs
+++ b/src/Text/Hakyll/Hakyll.hs
@@ -21,6 +21,8 @@ data HakyllConfiguration = HakyllConfiguration
cacheDirectory :: FilePath
, -- | Enable index links.
enableIndexUrl :: Bool
+ , -- | Delay between polls in preview mode.
+ previewPollDelay :: Int
}
-- | Our custom monad stack.
diff --git a/src/Text/Hakyll/Internal/Cache.hs b/src/Text/Hakyll/Internal/Cache.hs
index 0deb5f4..d586f45 100644
--- a/src/Text/Hakyll/Internal/Cache.hs
+++ b/src/Text/Hakyll/Internal/Cache.hs
@@ -27,4 +27,4 @@ getFromCache = liftIO . decodeFile <=< toCache
-- | Check if a file in the cache is more recent than a number of other files.
isCacheMoreRecent :: FilePath -> [FilePath] -> Hakyll Bool
-isCacheMoreRecent file depends = toCache file >>= flip isMoreRecent depends
+isCacheMoreRecent file depends = toCache file >>= flip isFileMoreRecent depends
diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs
index df0f553..34e1780 100644
--- a/src/Text/Hakyll/Render.hs
+++ b/src/Text/Hakyll/Render.hs
@@ -32,7 +32,7 @@ depends :: FilePath -- ^ File to be rendered or created.
-> Hakyll ()
depends file dependencies action = do
destination <- toDestination file
- valid <- isMoreRecent destination dependencies
+ valid <- isFileMoreRecent destination dependencies
unless valid action
-- | Render to a Page.