diff options
Diffstat (limited to 'src/Text/Hakyll/File.hs')
-rw-r--r-- | src/Text/Hakyll/File.hs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/Text/Hakyll/File.hs b/src/Text/Hakyll/File.hs index 0c803e1..400d156 100644 --- a/src/Text/Hakyll/File.hs +++ b/src/Text/Hakyll/File.hs @@ -4,6 +4,7 @@ module Text.Hakyll.File ( toDestination , toCache , toURL + , removeSpaces , makeDirectories , getRecursiveContents , havingExtension @@ -15,18 +16,31 @@ import System.Directory import System.FilePath import Control.Monad +-- | Auxiliary function to remove pathSeparators form the start. We don't deal +-- with absolute paths here. +removeLeadingSeparator :: FilePath -> FilePath +removeLeadingSeparator [] = [] +removeLeadingSeparator p@(x:xs) | x `elem` pathSeparators = xs + | otherwise = p + -- | Convert a relative filepath to a filepath in the destination (_site). toDestination :: FilePath -> FilePath -toDestination path = "_site" </> path +toDestination path = "_site" </> (removeLeadingSeparator path) -- | Convert a relative filepath to a filepath in the cache (_cache). toCache :: FilePath -> FilePath -toCache path = "_cache" </> path +toCache path = "_cache" </> (removeLeadingSeparator path) -- | Get the url for a given page. toURL :: FilePath -> FilePath toURL = flip addExtension ".html" . dropExtension +-- | Swaps spaces for '-'. +removeSpaces :: FilePath -> FilePath +removeSpaces = map swap + where swap ' ' = '-' + swap x = x + -- | Given a path to a file, try to make the path writable by making -- all directories on the path. makeDirectories :: FilePath -> IO () |