@@ -5,6 +5,7 @@ module Text.Hakyll.File
8 , inHakyllDirectory
9 , inHakyllDirectory
9 , removeSpaces
10 , removeSpaces
10 , makeDirectories
11 , makeDirectories
@@ -87,6 +88,15 @@ toRoot = emptyException . joinPath . map parent . splitPath
87 emptyException [] = "."
88 emptyException [] = "."
88 emptyException x = x
89 emptyException x = x
91+-- | Check if a file is in a given directory.
93+inDirectory :: FilePath -- ^ File path
94+ -> FilePath -- ^ Directory
96+inDirectory path dir = case splitDirectories path of
90-- | Check if a file is in a Hakyll directory. With a Hakyll directory, we mean
100-- | Check if a file is in a Hakyll directory. With a Hakyll directory, we mean
91-- a directory that should be "ignored" such as the @_site@ or @_cache@
101-- a directory that should be "ignored" such as the @_site@ or @_cache@
92-- directory.
102-- directory.
@@ -101,11 +111,8 @@ toRoot = emptyException . joinPath . map parent . splitPath
102inHakyllDirectory :: FilePath -> Hakyll Bool
112inHakyllDirectory :: FilePath -> Hakyll Bool
103inHakyllDirectory path =
113inHakyllDirectory path =
104− or <$> mapM (liftM inDirectory . askHakyll) [siteDirectory, cacheDirectory]
114+ or <$> mapM (liftM (inDirectory path) . askHakyll)
105− where
115+ [siteDirectory, cacheDirectory]
106− inDirectory dir = case splitDirectories path of
110-- | Swaps spaces for '-'.
117-- | Swaps spaces for '-'.
111removeSpaces :: FilePath -> FilePath
118removeSpaces :: FilePath -> FilePath
@@ -123,17 +130,21 @@ makeDirectories path = liftIO $ createDirectoryIfMissing True dir
124-- | Get all contents of a directory. Note that files starting with a dot (.)
131-- | Get all contents of a directory. Note that files starting with a dot (.)
125-- will be ignored.
132-- will be ignored.
126getRecursiveContents :: FilePath -> Hakyll [FilePath]
134getRecursiveContents :: FilePath -> Hakyll [FilePath]
127getRecursiveContents topdir = do
135getRecursiveContents topdir = do
136+ topdirExists <- liftIO $ doesDirectoryExist topdir
128− names <- liftIO $ getDirectoryContents topdir
138+ then do names <- liftIO $ getDirectoryContents topdir
129− let properNames = filter isProper names
139+ let properNames = filter isProper names
130− paths <- forM properNames $ \name -> do
140+ paths <- forM properNames $ \name -> do
131− let path = topdir </> name
141+ let path = topdir </> name
132− isDirectory <- liftIO $ doesDirectoryExist path
142+ isDirectory <- liftIO $ doesDirectoryExist path
133− if isDirectory
143+ if isDirectory
134− then getRecursiveContents path
144+ then getRecursiveContents path
135− else return [path]
145+ else return [normalise path]
136− return (concat paths)
146+ return (concat paths)
138 isProper = not . (== '.') . head
149 isProper = not . (== '.') . head