1-- | A module containing various function for manipulating and examinating
2-- files and directories.
15import System.Directory
19-- | Auxiliary function to remove pathSeparators form the start. We don't deal
20-- with absolute paths here.
21removeLeadingSeparator :: FilePath -> FilePath
22removeLeadingSeparator [] = []
23removeLeadingSeparator p@(x:xs) | x `elem` pathSeparators = xs
26-- | Convert a relative filepath to a filepath in the destination (_site).
27toDestination :: FilePath -> FilePath
28toDestination path = "_site" </> (removeLeadingSeparator path)
30-- | Convert a relative filepath to a filepath in the cache (_cache).
31toCache :: FilePath -> FilePath
32toCache path = "_cache" </> (removeLeadingSeparator path)
34-- | Get the url for a given page.
35toURL :: FilePath -> FilePath
36toURL = flip addExtension ".html" . dropExtension
38-- | Swaps spaces for '-'.
39removeSpaces :: FilePath -> FilePath
40removeSpaces = map swap
44-- | Given a path to a file, try to make the path writable by making
45-- all directories on the path.
46makeDirectories :: FilePath -> IO ()
47makeDirectories path = createDirectoryIfMissing True dir
48 where dir = takeDirectory path
50-- | Get all contents of a directory. Note that files starting with a dot (.)
52getRecursiveContents :: FilePath -> IO [FilePath]
53getRecursiveContents topdir = do
54 names <- getDirectoryContents topdir
55 let properNames = filter isProper names
56 paths <- forM properNames $ \name -> do
57 let path = topdir </> name
58 isDirectory <- doesDirectoryExist path
60 then getRecursiveContents path
63 where isProper = not . (== '.') . head
65-- | A filter that takes all file names with a given extension. Prefix the
66-- extension with a dot:
68-- > havingExtension ".markdown" ["index.markdown", "style.css"] == ["index.markdown"]
69havingExtension :: String -> [FilePath] -> [FilePath]
70havingExtension extension = filter ((==) extension . takeExtension)
72-- | Perform an IO action on every file in a given directory.
73directory :: (FilePath -> IO ()) -> FilePath -> IO ()
74directory action dir = getRecursiveContents dir >>= mapM_ action
76-- | Check if a cache file is still valid.
77isCacheValid :: FilePath -> [FilePath] -> IO Bool
78isCacheValid cache depends = doesFileExist cache >>= \exists ->
79 if not exists then return False
80 else do dependsModified <- (mapM getModificationTime depends) >>= return . maximum
81 cacheModified <- getModificationTime cache
82 return (cacheModified >= dependsModified)
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