1-- | A module containing various function for manipulating and examinating
2-- files and directories.
14import System.Directory
18-- | Convert a relative filepath to a filepath in the destination (_site).
19toDestination :: FilePath -> FilePath
20toDestination path = "_site" </> path
22-- | Convert a relative filepath to a filepath in the cache (_cache).
23toCache :: FilePath -> FilePath
24toCache path = "_cache" </> path
26-- | Get the url for a given page.
27toURL :: FilePath -> FilePath
28toURL = flip addExtension ".html" . dropExtension
30-- | Given a path to a file, try to make the path writable by making
31-- all directories on the path.
32makeDirectories :: FilePath -> IO ()
33makeDirectories path = createDirectoryIfMissing True dir
34 where dir = takeDirectory path
36-- | Get all contents of a directory. Note that files starting with a dot (.)
38getRecursiveContents :: FilePath -> IO [FilePath]
39getRecursiveContents topdir = do
40 names <- getDirectoryContents topdir
41 let properNames = filter isProper names
42 paths <- forM properNames $ \name -> do
43 let path = topdir </> name
44 isDirectory <- doesDirectoryExist path
46 then getRecursiveContents path
49 where isProper = not . (== '.') . head
51-- | A filter that takes all file names with a given extension. Prefix the
52-- extension with a dot:
53-- > havingExtension ".markdown" ["index.markdown", "style.css"] == ["index.markdown"]
54havingExtension :: String -> [FilePath] -> [FilePath]
55havingExtension extension = filter ((==) extension . takeExtension)
57-- | Perform an IO action on every file in a given directory.
58directory :: (FilePath -> IO ()) -> FilePath -> IO ()
59directory action dir = getRecursiveContents dir >>= mapM_ action
61-- | Check if a cache file is still valid.
62isCacheValid :: FilePath -> [FilePath] -> IO Bool
63isCacheValid cache depends = doesFileExist cache >>= \exists ->
64 if not exists then return False
65 else do dependsModified <- (mapM getModificationTime depends) >>= return . maximum
66 cacheModified <- getModificationTime cache
67 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