@@ -1,65 +1,23 @@
11module Text.Hakyll.Util
2− ( toDestination,
3− toCache,
4− toURL,
5− makeDirectories,
6− getRecursiveContents,
7− trim,
2+ ( trim,
83 split,
9− stripHtml,
10− isCacheValid
4+ stripHTML
115 ) where
126
13−import System.Directory
14−import System.FilePath
15−import Control.Monad
167import Data.Char
178import Data.List
189
19−-- | Convert a relative filepath to a filepath in the destination (_site).
20−toDestination :: FilePath -> FilePath
21−toDestination path = "_site" </> path
22−
23−-- | Convert a relative filepath to a filepath in the cache (_cache).
24−toCache :: FilePath -> FilePath
25−toCache path = "_cache" </> path
26−
27−-- | Get the url for a given page.
28−toURL :: FilePath -> FilePath
29−toURL = flip addExtension ".html" . dropExtension
30−
31−-- | Given a path to a file, try to make the path writable by making
32−-- all directories on the path.
33−makeDirectories :: FilePath -> IO ()
34−makeDirectories path = createDirectoryIfMissing True dir
35− where dir = takeDirectory path
36−
37−-- | Get all contents of a directory. Note that files starting with a dot (.)
38−-- will be ignored.
39−getRecursiveContents :: FilePath -> IO [FilePath]
40−getRecursiveContents topdir = do
41− names <- getDirectoryContents topdir
42− let properNames = filter isProper names
43− paths <- forM properNames $ \name -> do
44− let path = topdir </> name
45− isDirectory <- doesDirectoryExist path
46− if isDirectory
47− then getRecursiveContents path
48− else return [path]
49− return (concat paths)
50− where isProper = not . (== '.') . head
51−
5210-- | Trim a string (drop spaces and tabs at both sides).
5311trim :: String -> String
5412trim = reverse . trim' . reverse . trim'
5513 where trim' = dropWhile isSpace
5614
5715-- | Strip html tags.
58−stripHtml :: String -> String
59−stripHtml [] = []
60−stripHtml str = let (beforeTag, rest) = break (== '<') str
16+stripHTML :: String -> String
17+stripHTML [] = []
18+stripHTML str = let (beforeTag, rest) = break (== '<') str
6119 (_, afterTag) = break (== '>') rest
62− in beforeTag ++ (stripHtml $ tail' afterTag)
20+ in beforeTag ++ (stripHTML $ tail' afterTag)
6321 -- We need a failsafe tail function.
6422 where tail' [] = []
6523 tail' xs = tail xs
@@ -72,11 +30,3 @@ split element = unfoldr splitOnce
7230 (x, xs) -> if null xs
7331 then Just (x, [])
7432 else Just (x, tail xs)
75−
76−-- | Check is a cache file is still valid.
77−isCacheValid :: FilePath -> [FilePath] -> IO Bool
78−isCacheValid cache depends = doesFileExist cache >>= \exists ->
79− if not exists then return False
80− else do dependsModified <- (mapM getModificationTime depends) >>= return . maximum
81− cacheModified <- getModificationTime cache
82− return (cacheModified >= dependsModified)