@@ -1,65 +1,23 @@
1module Text.Hakyll.Util
1module Text.Hakyll.Util
9− stripHtml,
4+ stripHTML
13−import System.Directory
14−import System.FilePath
16import Data.Char
7import Data.Char
17import Data.List
8import Data.List
19−-- | Convert a relative filepath to a filepath in the destination (_site).
20−toDestination :: FilePath -> FilePath
21−toDestination path = "_site" </> path
23−-- | Convert a relative filepath to a filepath in the cache (_cache).
24−toCache :: FilePath -> FilePath
25−toCache path = "_cache" </> path
27−-- | Get the url for a given page.
28−toURL :: FilePath -> FilePath
29−toURL = flip addExtension ".html" . dropExtension
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
37−-- | Get all contents of a directory. Note that files starting with a dot (.)
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
47− then getRecursiveContents path
49− return (concat paths)
50− where isProper = not . (== '.') . head
52-- | Trim a string (drop spaces and tabs at both sides).
10-- | Trim a string (drop spaces and tabs at both sides).
53trim :: String -> String
11trim :: String -> String
54trim = reverse . trim' . reverse . trim'
12trim = reverse . trim' . reverse . trim'
55 where trim' = dropWhile isSpace
13 where trim' = dropWhile isSpace
57-- | Strip html tags.
15-- | Strip html tags.
58−stripHtml :: String -> String
16+stripHTML :: String -> String
59−stripHtml [] = []
17+stripHTML [] = []
60−stripHtml str = let (beforeTag, rest) = break (== '<') str
18+stripHTML str = let (beforeTag, rest) = break (== '<') str
61 (_, afterTag) = break (== '>') rest
19 (_, afterTag) = break (== '>') rest
62− in beforeTag ++ (stripHtml $ tail' afterTag)
20+ in beforeTag ++ (stripHTML $ tail' afterTag)
63 -- We need a failsafe tail function.
21 -- We need a failsafe tail function.
64 where tail' [] = []
22 where tail' [] = []
65 tail' xs = tail xs
23 tail' xs = tail xs
@@ -72,11 +30,3 @@ split element = unfoldr splitOnce
72 (x, xs) -> if null xs
30 (x, xs) -> if null xs
73 then Just (x, [])
31 then Just (x, [])
74 else Just (x, tail xs)
32 else Just (x, tail xs)
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)