1-- | A module containing various file utility functions
3module Hakyll.Core.Util.File
9import Control.Applicative ((<$>))
10import Control.Monad (forM)
11import Data.List (isPrefixOf)
12import System.Directory ( createDirectoryIfMissing, doesDirectoryExist
13 , getDirectoryContents
15import System.FilePath ( normalise, takeDirectory, splitPath
16 , dropTrailingPathSeparator, (</>)
19import Hakyll.Core.Configuration
21-- | Given a path to a file, try to make the path writable by making
22-- all directories on the path.
24makeDirectories :: FilePath -> IO ()
25makeDirectories = createDirectoryIfMissing True . takeDirectory
27-- | Get all contents of a directory.
28getRecursiveContents :: Bool -- ^ Include directories?
29 -> FilePath -- ^ Directory to search
30 -> IO [FilePath] -- ^ List of files found
31getRecursiveContents includeDirs topdir = do
32 topdirExists <- doesDirectoryExist topdir
36 names <- filter isProper <$> getDirectoryContents topdir
37 paths <- forM names $ \name -> do
38 let path = normalise $ topdir </> name
39 isDirectory <- doesDirectoryExist path
40 if isDirectory then getRecursiveContents includeDirs path
42 return $ if includeDirs then topdir : concat paths
45 isProper = (`notElem` [".", ".."])
47-- | Check if a file is meant for Hakyll internal use, i.e. if it is located in
48-- the destination or store directory
50isFileInternal :: HakyllConfiguration -- ^ Configuration
51 -> FilePath -- ^ File to check
52 -> Bool -- ^ If the given file is internal
53isFileInternal configuration file =
54 any (`isPrefixOf` split file) dirs
56 split = map dropTrailingPathSeparator . splitPath
57 dirs = map (split . ($ configuration)) [ destinationDirectory
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list