1-- | A module containing various function for manipulating and examinating
2-- files and directories.
10 , getRecursiveContents
16import System.Directory
19import Data.List (isPrefixOf)
20import Control.Monad.Reader (liftIO)
22import Text.Hakyll.Hakyll
24-- | Auxiliary function to remove pathSeparators form the start. We don't deal
25-- with absolute paths here. We also remove $root from the start.
26removeLeadingSeparator :: FilePath -> FilePath
27removeLeadingSeparator [] = []
28removeLeadingSeparator path
29 | head path' `elem` pathSeparators = tail path'
32 path' = if "$root" `isPrefixOf` path then drop 5 path
35-- | Convert a relative filepath to a filepath in the destination
37toDestination :: FilePath -> Hakyll FilePath
38toDestination path = do dir <- askHakyll siteDirectory
39 return $ dir </> removeLeadingSeparator path
41-- | Convert a relative filepath to a filepath in the cache
42-- (default: @_cache@).
43toCache :: FilePath -> Hakyll FilePath
44toCache path = do dir <- askHakyll cacheDirectory
45 return $ dir </> removeLeadingSeparator path
47-- | Get the url for a given page.
48toURL :: FilePath -> FilePath
49toURL path = if takeExtension path `elem` [ ".markdown"
60 then flip addExtension ".html" $ dropExtension path
63-- | Get the relative url to the site root, for a given (absolute) url
64toRoot :: FilePath -> FilePath
65toRoot = emptyException . joinPath . map parent . splitPath
66 . takeDirectory . removeLeadingSeparator
69 emptyException [] = "."
72-- | Swaps spaces for '-'.
73removeSpaces :: FilePath -> FilePath
74removeSpaces = map swap
79-- | Given a path to a file, try to make the path writable by making
80-- all directories on the path.
81makeDirectories :: FilePath -> Hakyll ()
82makeDirectories path = liftIO $ createDirectoryIfMissing True dir
84 dir = takeDirectory path
86-- | Get all contents of a directory. Note that files starting with a dot (.)
88getRecursiveContents :: FilePath -> Hakyll [FilePath]
89getRecursiveContents topdir = do
90 names <- liftIO $ getDirectoryContents topdir
91 let properNames = filter isProper names
92 paths <- forM properNames $ \name -> do
93 let path = topdir </> name
94 isDirectory <- liftIO $ doesDirectoryExist path
96 then getRecursiveContents path
100 isProper = not . (== '.') . head
102-- | A filter that takes all file names with a given extension. Prefix the
103-- extension with a dot:
105-- > havingExtension ".markdown" [ "index.markdown"
107-- > ] == ["index.markdown"]
108havingExtension :: String -> [FilePath] -> [FilePath]
109havingExtension extension = filter ((==) extension . takeExtension)
111-- | Perform a Hakyll action on every file in a given directory.
112directory :: (FilePath -> Hakyll ()) -> FilePath -> Hakyll ()
113directory action dir = getRecursiveContents dir >>= mapM_ action
115-- | Check if a file is newer then a number of given files.
116isMoreRecent :: FilePath -- ^ The cached file.
117 -> [FilePath] -- ^ Dependencies of the cached file.
119isMoreRecent file depends = do
120 exists <- liftIO $ doesFileExist file
123 else do dependsModified <- liftIO $ mapM getModificationTime depends
124 fileModified <- liftIO $ getModificationTime file
125 return (fileModified >= maximum 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