12import System.Directory
18toDestination :: FilePath -> FilePath
19toDestination path = "_site" </> path
21toCache :: FilePath -> FilePath
22toCache path = "_cache" </> path
24-- | Get the url for a given page.
25toURL :: FilePath -> FilePath
26toURL = flip addExtension ".html" . dropExtension
28-- | Given a path to a file, try to make the path writable by making
29-- all directories on the path.
30makeDirectories :: FilePath -> IO ()
31makeDirectories path = createDirectoryIfMissing True dir
32 where dir = takeDirectory path
34-- | Get all contents of a directory. Note that files starting with a dot (.)
36getRecursiveContents :: FilePath -> IO [FilePath]
37getRecursiveContents topdir = do
38 names <- getDirectoryContents topdir
39 let properNames = filter isProper names
40 paths <- forM properNames $ \name -> do
41 let path = topdir </> name
42 isDirectory <- doesDirectoryExist path
44 then getRecursiveContents path
47 where isProper = not . (== '.') . head
49-- | Trim a string (drop spaces and tabs at both sides).
50trim :: String -> String
51trim = reverse . trim' . reverse . trim'
52 where trim' = dropWhile isSpace
54-- | Split a list at a certain element.
55split :: (Eq a) => a -> [a] -> [[a]]
56split element = unfoldr splitOnce
57 where splitOnce l = let r = break (== element) l
58 in case r of ([], []) -> Nothing
61 else Just (x, tail xs)
63-- | Check is a cache file is still valid.
64isCacheValid :: FilePath -> [FilePath] -> IO Bool
65isCacheValid cache depends = doesFileExist cache >>= \exists ->
66 if not exists then return False
67 else do dependsModified <- (mapM getModificationTime depends) >>= return . maximum
68 cacheModified <- getModificationTime cache
69 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