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:
54-- > havingExtension ".markdown" ["index.markdown", "style.css"] == ["index.markdown"]
55havingExtension :: String -> [FilePath] -> [FilePath]
56havingExtension extension = filter ((==) extension . takeExtension)
58-- | Perform an IO action on every file in a given directory.
59directory :: (FilePath -> IO ()) -> FilePath -> IO ()
60directory action dir = getRecursiveContents dir >>= mapM_ action
62-- | Check if a cache file is still valid.
63isCacheValid :: FilePath -> [FilePath] -> IO Bool
64isCacheValid cache depends = doesFileExist cache >>= \exists ->
65 if not exists then return False
66 else do dependsModified <- (mapM getModificationTime depends) >>= return . maximum
67 cacheModified <- getModificationTime cache
68 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