diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-02-12 12:01:23 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-02-12 12:01:23 +0100 |
commit | 6611e86ac5db5790b271f0b3e41376a0affdbb80 (patch) | |
tree | 5b2f5cc7d58a3fd7b41e8ee57a167407a6f86be4 /src/Text/Hakyll/File.hs | |
parent | 732fdc9894fe8002c91b309ba8aeafc99e9f5be3 (diff) | |
download | hakyll-6611e86ac5db5790b271f0b3e41376a0affdbb80.tar.gz |
Added autocompile mode to replace preview mode.
Diffstat (limited to 'src/Text/Hakyll/File.hs')
-rw-r--r-- | src/Text/Hakyll/File.hs | 24 |
1 files changed, 17 insertions, 7 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 |