summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Util.hs
blob: f5a99543873ff484d56bcf5e8ac123641eb30a57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Text.Hakyll.Util 
    ( touchDirectories,
      getRecursiveContents
    ) where

import System.Directory
import System.FilePath
import Control.Monad

touchDirectories :: FilePath -> IO ()
touchDirectories path = createDirectoryIfMissing True dir
    where dir = takeDirectory path

getRecursiveContents :: FilePath -> IO [FilePath]
getRecursiveContents topdir = do
    names <- getDirectoryContents topdir
    let properNames = filter isProper names
    paths <- forM properNames $ \name -> do
        let path = topdir </> name
        isDirectory <- doesDirectoryExist path
        if isDirectory
            then getRecursiveContents path
            else return [path]
    return (concat paths)
    where isProper = not . (== '.') . head