summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-20 16:46:22 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-20 16:46:22 +0100
commit8602f23f7bcdcc3bec65ec98c70ee3f295482856 (patch)
tree8f86b9cb541ba0c4f1167a2211db090480d2f5b2 /src/Text/Hakyll.hs
parentd79022fb3481dd2f6c2c0d9112c6c6f37c71204e (diff)
downloadhakyll-8602f23f7bcdcc3bec65ec98c70ee3f295482856.tar.gz
Made site and cache directory configurable. Caching stubs.
Diffstat (limited to 'src/Text/Hakyll.hs')
-rw-r--r--src/Text/Hakyll.hs45
1 files changed, 21 insertions, 24 deletions
diff --git a/src/Text/Hakyll.hs b/src/Text/Hakyll.hs
index c0486e7..33b1b57 100644
--- a/src/Text/Hakyll.hs
+++ b/src/Text/Hakyll.hs
@@ -4,7 +4,7 @@ module Text.Hakyll
, hakyllWithConfiguration
) where
-import Control.Monad.Reader (runReaderT)
+import Control.Monad.Reader (runReaderT, liftIO)
import Control.Monad (when)
import qualified Data.Map as M
import System.Environment (getArgs, getProgName)
@@ -17,6 +17,8 @@ import Text.Hakyll.Hakyll
defaultHakyllConfiguration :: HakyllConfiguration
defaultHakyllConfiguration = HakyllConfiguration
{ additionalContext = M.empty
+ , siteDirectory = "_site"
+ , cacheDirectory = "_cache"
}
-- | Hakyll with a default configuration.
@@ -27,32 +29,27 @@ hakyll = hakyllWithConfiguration defaultHakyllConfiguration
hakyllWithConfiguration :: HakyllConfiguration -> Hakyll () -> IO ()
hakyllWithConfiguration configuration buildFunction = do
args <- getArgs
- case args of ["build"] -> build'
- ["clean"] -> clean
- ["preview", p] -> build' >> server (read p)
- ["preview"] -> build' >> server 8000
- ["server", p] -> server (read p)
- ["server"] -> server 8000
- _ -> help
- where
- build' = build configuration buildFunction
-
--- | Build the site.
-build :: HakyllConfiguration -> Hakyll () -> IO ()
-build configuration buildFunction = do putStrLn "Generating..."
- runReaderT buildFunction configuration
+ let f = case args of ["build"] -> buildFunction
+ ["clean"] -> clean
+ ["preview", p] -> buildFunction >> server (read p)
+ ["preview"] -> buildFunction >> server 8000
+ ["server", p] -> server (read p)
+ ["server"] -> server 8000
+ _ -> help
+ runReaderT f configuration
-- | Clean up directories.
-clean :: IO ()
-clean = remove' "_site"
+clean :: Hakyll ()
+clean = do askHakyll siteDirectory >>= remove'
+ askHakyll cacheDirectory >>= remove'
where
- remove' dir = do putStrLn $ "Removing " ++ dir ++ "..."
- exists <- doesDirectoryExist dir
- when exists $ removeDirectoryRecursive dir
+ remove' dir = liftIO $ do putStrLn $ "Removing " ++ dir ++ "..."
+ exists <- doesDirectoryExist dir
+ when exists $ removeDirectoryRecursive dir
-- | Show usage information.
-help :: IO ()
-help = do
+help :: Hakyll ()
+help = liftIO $ do
name <- getProgName
putStrLn $ "This is a Hakyll site generator program. You should always\n"
++ "run it from the project root directory.\n"
@@ -64,5 +61,5 @@ help = do
++ name ++ " preview [port] Generate site, then start a server.\n"
++ name ++ " server [port] Run a local test server.\n"
-server :: Integer -> IO ()
-server p = simpleServer (fromIntegral p) "_site"
+server :: Integer -> Hakyll ()
+server p = askHakyll siteDirectory >>= liftIO . simpleServer (fromIntegral p)