summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-08-06 19:18:01 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-08-06 19:18:01 +0200
commit10646840ac31b1c6e7a9b4e6d8322f321af2678b (patch)
tree50eb21b031bc05a866cbf101486c634e71c72fec /src/Hakyll
parent4e3238d4393d6862ac04c51cc7ca0810d7dd7ec8 (diff)
downloadhakyll-10646840ac31b1c6e7a9b4e6d8322f321af2678b.tar.gz
Add a flag to disable the preview server
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Main.hs42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/Hakyll/Main.hs b/src/Hakyll/Main.hs
index ef5c4c8..d97dc31 100644
--- a/src/Hakyll/Main.hs
+++ b/src/Hakyll/Main.hs
@@ -1,25 +1,30 @@
-- | Module providing the main hakyll function and command-line argument parsing
--
+{-# LANGUAGE CPP #-}
module Hakyll.Main
( hakyll
, hakyllWith
) where
-import Control.Applicative ((<$>))
-import Control.Concurrent (forkIO)
import Control.Monad (when)
import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
import System.Environment (getProgName, getArgs)
import System.Process (system)
-import qualified Data.Set as S
import Hakyll.Core.Configuration
-import Hakyll.Core.Resource
import Hakyll.Core.Run
import Hakyll.Core.Rules
+
+#ifdef PREVIEW_SERVER
+import Control.Applicative ((<$>))
+import Control.Concurrent (forkIO)
+import qualified Data.Set as S
+
+import Hakyll.Core.Resource
import Hakyll.Core.Rules.Internal
import Hakyll.Web.Preview.Poll
import Hakyll.Web.Preview.Server
+#endif
-- | This usualy is the function with which the user runs the hakyll compiler
--
@@ -83,11 +88,17 @@ help = do
, name ++ " rebuild Clean up and build again"
, name ++ " server [port] Run a local test server"
, name ++ " deploy Upload/deploy your site"
+ , ""
]
+#ifndef PREVIEW_SERVER
+ previewServerDisabled
+#endif
+
-- | Preview the site
--
preview :: HakyllConfiguration -> RulesM a -> Int -> IO ()
+#ifdef PREVIEW_SERVER
preview conf rules port = do
-- Fork a thread polling for changes
_ <- forkIO $ previewPoll conf update
@@ -96,6 +107,9 @@ preview conf rules port = do
server conf port
where
update = map unResource . S.toList . rulesResources <$> run conf rules
+#else
+preview _ _ _ = previewServerDisabled
+#endif
-- | Rebuild the site
--
@@ -107,15 +121,33 @@ rebuild conf rules = do
-- | Start a server
--
server :: HakyllConfiguration -> Int -> IO ()
+#ifdef PREVIEW_SERVER
server conf port = do
let destination = destinationDirectory conf
staticServer destination preServeHook port
where
preServeHook _ = return ()
+#else
+server _ _ = previewServerDisabled
+#endif
--- Upload the site
+-- | Upload the site
--
deploy :: HakyllConfiguration -> IO ()
deploy conf = do
_ <- system $ deployCommand conf
return ()
+
+-- | Print a warning message about the preview serving not being enabled
+--
+#ifndef PREVIEW_SERVER
+previewServerDisabled :: IO ()
+previewServerDisabled =
+ mapM_ putStrLn
+ [ "PREVIEW SERVER"
+ , ""
+ , "The preview server is not enabled in the version of Hakyll. To"
+ , "enable it, set the flag to True and recompile Hakyll."
+ , "Alternatively, use an external tool to serve your site directory."
+ ]
+#endif