summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-17 20:08:42 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-17 20:08:42 +0100
commit221c029dad1cef555b0540b152ec167e90937b16 (patch)
tree463c604c2f9f223616246383517500c6ae0c7214 /src/Text/Hakyll
parent6bbf514c77205b04c0b9ee38a0f6298e3e52e85a (diff)
downloadhakyll-221c029dad1cef555b0540b152ec167e90937b16.tar.gz
Splitted Text.Hakyll.Util into Text.Hakyll.File and Text.Hakyll.Util.
Diffstat (limited to 'src/Text/Hakyll')
-rw-r--r--src/Text/Hakyll/File.hs55
-rw-r--r--src/Text/Hakyll/Page.hs1
-rw-r--r--src/Text/Hakyll/Render.hs2
-rw-r--r--src/Text/Hakyll/Renderables.hs2
-rw-r--r--src/Text/Hakyll/Util.hs62
5 files changed, 64 insertions, 58 deletions
diff --git a/src/Text/Hakyll/File.hs b/src/Text/Hakyll/File.hs
new file mode 100644
index 0000000..07464ac
--- /dev/null
+++ b/src/Text/Hakyll/File.hs
@@ -0,0 +1,55 @@
+-- | A module containing various function for manipulating and examinating
+-- files and directories.
+module Text.Hakyll.File
+ ( toDestination,
+ toCache,
+ toURL,
+ makeDirectories,
+ getRecursiveContents,
+ isCacheValid
+ ) where
+
+import System.Directory
+import System.FilePath
+import Control.Monad
+
+-- | Convert a relative filepath to a filepath in the destination (_site).
+toDestination :: FilePath -> FilePath
+toDestination path = "_site" </> path
+
+-- | Convert a relative filepath to a filepath in the cache (_cache).
+toCache :: FilePath -> FilePath
+toCache path = "_cache" </> path
+
+-- | Get the url for a given page.
+toURL :: FilePath -> FilePath
+toURL = flip addExtension ".html" . dropExtension
+
+-- | Given a path to a file, try to make the path writable by making
+-- all directories on the path.
+makeDirectories :: FilePath -> IO ()
+makeDirectories path = createDirectoryIfMissing True dir
+ where dir = takeDirectory path
+
+-- | Get all contents of a directory. Note that files starting with a dot (.)
+-- will be ignored.
+getRecursiveContents :: FilePath -> IO [FilePath]
+getRecursiveContents topdir = do
+ names <- getDirectoryContents topdir
+ let properNames = filter isProper names
+ paths <- forM properNames $ \name -> do
+ let path = topdir </> name
+ isDirectory <- doesDirectoryExist path
+ if isDirectory
+ then getRecursiveContents path
+ else return [path]
+ return (concat paths)
+ where isProper = not . (== '.') . head
+
+-- | Check is a cache file is still valid.
+isCacheValid :: FilePath -> [FilePath] -> IO Bool
+isCacheValid cache depends = doesFileExist cache >>= \exists ->
+ if not exists then return False
+ else do dependsModified <- (mapM getModificationTime depends) >>= return . maximum
+ cacheModified <- getModificationTime cache
+ return (cacheModified >= dependsModified)
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs
index 1590de2..ae1a2ea 100644
--- a/src/Text/Hakyll/Page.hs
+++ b/src/Text/Hakyll/Page.hs
@@ -15,6 +15,7 @@ import Control.Monad
import System.FilePath
import System.IO
+import Text.Hakyll.File
import Text.Hakyll.Util
import Text.Hakyll.Renderable
import Text.Pandoc
diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs
index a94ac2d..87467f7 100644
--- a/src/Text/Hakyll/Render.hs
+++ b/src/Text/Hakyll/Render.hs
@@ -17,7 +17,7 @@ import System.IO
import Text.Hakyll.Page
import Text.Hakyll.Renderable
-import Text.Hakyll.Util
+import Text.Hakyll.File
-- | Execute an IO action only when the cache is invalid.
depends :: FilePath -- ^ File to be rendered or created.
diff --git a/src/Text/Hakyll/Renderables.hs b/src/Text/Hakyll/Renderables.hs
index 47ef5db..c79df76 100644
--- a/src/Text/Hakyll/Renderables.hs
+++ b/src/Text/Hakyll/Renderables.hs
@@ -9,9 +9,9 @@ import System.FilePath
import qualified Data.ByteString.Lazy.Char8 as B
import qualified Data.Map as M
import Control.Monad
-import Text.Hakyll.Util
import Text.Hakyll.Page
import Text.Hakyll.Renderable
+import Text.Hakyll.File
-- | A custom page.
data CustomPage = CustomPage
diff --git a/src/Text/Hakyll/Util.hs b/src/Text/Hakyll/Util.hs
index 35f7b33..aaa2952 100644
--- a/src/Text/Hakyll/Util.hs
+++ b/src/Text/Hakyll/Util.hs
@@ -1,65 +1,23 @@
module Text.Hakyll.Util
- ( toDestination,
- toCache,
- toURL,
- makeDirectories,
- getRecursiveContents,
- trim,
+ ( trim,
split,
- stripHtml,
- isCacheValid
+ stripHTML
) where
-import System.Directory
-import System.FilePath
-import Control.Monad
import Data.Char
import Data.List
--- | Convert a relative filepath to a filepath in the destination (_site).
-toDestination :: FilePath -> FilePath
-toDestination path = "_site" </> path
-
--- | Convert a relative filepath to a filepath in the cache (_cache).
-toCache :: FilePath -> FilePath
-toCache path = "_cache" </> path
-
--- | Get the url for a given page.
-toURL :: FilePath -> FilePath
-toURL = flip addExtension ".html" . dropExtension
-
--- | Given a path to a file, try to make the path writable by making
--- all directories on the path.
-makeDirectories :: FilePath -> IO ()
-makeDirectories path = createDirectoryIfMissing True dir
- where dir = takeDirectory path
-
--- | Get all contents of a directory. Note that files starting with a dot (.)
--- will be ignored.
-getRecursiveContents :: FilePath -> IO [FilePath]
-getRecursiveContents topdir = do
- names <- getDirectoryContents topdir
- let properNames = filter isProper names
- paths <- forM properNames $ \name -> do
- let path = topdir </> name
- isDirectory <- doesDirectoryExist path
- if isDirectory
- then getRecursiveContents path
- else return [path]
- return (concat paths)
- where isProper = not . (== '.') . head
-
-- | Trim a string (drop spaces and tabs at both sides).
trim :: String -> String
trim = reverse . trim' . reverse . trim'
where trim' = dropWhile isSpace
-- | Strip html tags.
-stripHtml :: String -> String
-stripHtml [] = []
-stripHtml str = let (beforeTag, rest) = break (== '<') str
+stripHTML :: String -> String
+stripHTML [] = []
+stripHTML str = let (beforeTag, rest) = break (== '<') str
(_, afterTag) = break (== '>') rest
- in beforeTag ++ (stripHtml $ tail' afterTag)
+ in beforeTag ++ (stripHTML $ tail' afterTag)
-- We need a failsafe tail function.
where tail' [] = []
tail' xs = tail xs
@@ -72,11 +30,3 @@ split element = unfoldr splitOnce
(x, xs) -> if null xs
then Just (x, [])
else Just (x, tail xs)
-
--- | Check is a cache file is still valid.
-isCacheValid :: FilePath -> [FilePath] -> IO Bool
-isCacheValid cache depends = doesFileExist cache >>= \exists ->
- if not exists then return False
- else do dependsModified <- (mapM getModificationTime depends) >>= return . maximum
- cacheModified <- getModificationTime cache
- return (cacheModified >= dependsModified)