1-- | A module containing various function for manipulating and examinating
2-- files and directories.
13import System.Directory
17-- | Convert a relative filepath to a filepath in the destination (_site).
18toDestination :: FilePath -> FilePath
19toDestination path = "_site" </> path
21-- | Convert a relative filepath to a filepath in the cache (_cache).
22toCache :: FilePath -> FilePath
23toCache path = "_cache" </> path
25-- | Get the url for a given page.
26toURL :: FilePath -> FilePath
27toURL = flip addExtension ".html" . dropExtension
29-- | Given a path to a file, try to make the path writable by making
30-- all directories on the path.
31makeDirectories :: FilePath -> IO ()
32makeDirectories path = createDirectoryIfMissing True dir
33 where dir = takeDirectory path
35-- | Get all contents of a directory. Note that files starting with a dot (.)
37getRecursiveContents :: FilePath -> IO [FilePath]
38getRecursiveContents topdir = do
39 names <- getDirectoryContents topdir
40 let properNames = filter isProper names
41 paths <- forM properNames $ \name -> do
42 let path = topdir </> name
43 isDirectory <- doesDirectoryExist path
45 then getRecursiveContents path
48 where isProper = not . (== '.') . head
50-- | Perform an IO action on every file in a given directory.
51directory :: (FilePath -> IO ()) -> FilePath -> IO ()
52directory action dir = getRecursiveContents dir >>= mapM_ action
54-- | Check is a cache file is still valid.
55isCacheValid :: FilePath -> [FilePath] -> IO Bool
56isCacheValid cache depends = doesFileExist cache >>= \exists ->
57 if not exists then return False
58 else do dependsModified <- (mapM getModificationTime depends) >>= return . maximum
59 cacheModified <- getModificationTime cache
60 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