summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/File.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-15 09:47:07 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-15 09:47:07 +0100
commit62330ceae51ea28f75768196ad5e3f93eb88b8a3 (patch)
treea3a45aa9e0d63c65eb4fc4e7a4277fde645b8f48 /src/Text/Hakyll/File.hs
parenta180016488d0fed843f525db824dc0c24cde90ca (diff)
downloadhakyll-62330ceae51ea28f75768196ad5e3f93eb88b8a3.tar.gz
Moved some more functions from the IO monad to the Hakyll monad stack.
Diffstat (limited to 'src/Text/Hakyll/File.hs')
-rw-r--r--src/Text/Hakyll/File.hs32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/Text/Hakyll/File.hs b/src/Text/Hakyll/File.hs
index 3dd2538..ed2bbea 100644
--- a/src/Text/Hakyll/File.hs
+++ b/src/Text/Hakyll/File.hs
@@ -63,20 +63,20 @@ removeSpaces = map swap
-- | Given a path to a file, try to make the path writable by making
-- all directories on the path.
-makeDirectories :: FilePath -> IO ()
-makeDirectories path = createDirectoryIfMissing True dir
+makeDirectories :: FilePath -> Hakyll ()
+makeDirectories path = liftIO $ createDirectoryIfMissing True dir
where
dir = takeDirectory path
-- | Get all contents of a directory. Note that files starting with a dot (.)
-- will be ignored.
-getRecursiveContents :: FilePath -> IO [FilePath]
+getRecursiveContents :: FilePath -> Hakyll [FilePath]
getRecursiveContents topdir = do
- names <- getDirectoryContents topdir
+ names <- liftIO $ getDirectoryContents topdir
let properNames = filter isProper names
paths <- forM properNames $ \name -> do
let path = topdir </> name
- isDirectory <- doesDirectoryExist path
+ isDirectory <- liftIO $ doesDirectoryExist path
if isDirectory
then getRecursiveContents path
else return [path]
@@ -87,20 +87,24 @@ getRecursiveContents topdir = do
-- | A filter that takes all file names with a given extension. Prefix the
-- extension with a dot:
--
--- > havingExtension ".markdown" ["index.markdown", "style.css"] == ["index.markdown"]
+-- > havingExtension ".markdown" [ "index.markdown"
+-- > , "style.css"
+-- > ] == ["index.markdown"]
havingExtension :: String -> [FilePath] -> [FilePath]
havingExtension extension = filter ((==) extension . takeExtension)
--- | Perform an IO action on every file in a given directory.
+-- | Perform a Hakyll action on every file in a given directory.
directory :: (FilePath -> Hakyll ()) -> FilePath -> Hakyll ()
directory action dir = do
- contents <- liftIO $ getRecursiveContents dir
+ contents <- getRecursiveContents dir
mapM_ action contents
-- | Check if a cache file is still valid.
-isCacheValid :: FilePath -> [FilePath] -> IO Bool
-isCacheValid cache depends = doesFileExist cache >>= \exists ->
- if not exists then return False
- else do dependsModified <- (mapM getModificationTime depends) >>= return . maximum
- cacheModified <- getModificationTime cache
- return (cacheModified >= dependsModified)
+isCacheValid :: FilePath -> [FilePath] -> Hakyll Bool
+isCacheValid cache depends = do
+ exists <- liftIO $ doesFileExist cache
+ if not exists
+ then return False
+ else do dependsModified <- liftIO $ mapM getModificationTime depends
+ cacheModified <- liftIO $ getModificationTime cache
+ return (cacheModified >= maximum dependsModified)