@@ -1,25 +1,30 @@
11-- | Module providing the main hakyll function and command-line argument parsing
22--
3+{-# LANGUAGE CPP #-}
34module Hakyll.Main
45 ( hakyll
56 , hakyllWith
67 ) where
78
8−import Control.Applicative ((<$>))
9−import Control.Concurrent (forkIO)
109import Control.Monad (when)
1110import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
1211import System.Environment (getProgName, getArgs)
1312import System.Process (system)
14−import qualified Data.Set as S
1513
1614import Hakyll.Core.Configuration
17−import Hakyll.Core.Resource
1815import Hakyll.Core.Run
1916import Hakyll.Core.Rules
17+
18+#ifdef PREVIEW_SERVER
19+import Control.Applicative ((<$>))
20+import Control.Concurrent (forkIO)
21+import qualified Data.Set as S
22+
23+import Hakyll.Core.Resource
2024import Hakyll.Core.Rules.Internal
2125import Hakyll.Web.Preview.Poll
2226import Hakyll.Web.Preview.Server
27+#endif
2328
2429-- | This usualy is the function with which the user runs the hakyll compiler
2530--
@@ -83,11 +88,17 @@ help = do
8388 , name ++ " rebuild Clean up and build again"
8489 , name ++ " server [port] Run a local test server"
8590 , name ++ " deploy Upload/deploy your site"
91+ , ""
8692 ]
8793
94+#ifndef PREVIEW_SERVER
95+ previewServerDisabled
96+#endif
97+
8898-- | Preview the site
8999--
90100preview :: HakyllConfiguration -> RulesM a -> Int -> IO ()
101+#ifdef PREVIEW_SERVER
91102preview conf rules port = do
92103 -- Fork a thread polling for changes
93104 _ <- forkIO $ previewPoll conf update
@@ -96,6 +107,9 @@ preview conf rules port = do
96107 server conf port
97108 where
98109 update = map unResource . S.toList . rulesResources <$> run conf rules
110+#else
111+preview _ _ _ = previewServerDisabled
112+#endif
99113
100114-- | Rebuild the site
101115--
@@ -107,15 +121,33 @@ rebuild conf rules = do
107121-- | Start a server
108122--
109123server :: HakyllConfiguration -> Int -> IO ()
124+#ifdef PREVIEW_SERVER
110125server conf port = do
111126 let destination = destinationDirectory conf
112127 staticServer destination preServeHook port
113128 where
114129 preServeHook _ = return ()
130+#else
131+server _ _ = previewServerDisabled
132+#endif
115133
116−-- Upload the site
134+-- | Upload the site
117135--
118136deploy :: HakyllConfiguration -> IO ()
119137deploy conf = do
120138 _ <- system $ deployCommand conf
121139 return ()
140+
141+-- | Print a warning message about the preview serving not being enabled
142+--
143+#ifndef PREVIEW_SERVER
144+previewServerDisabled :: IO ()
145+previewServerDisabled =
146+ mapM_ putStrLn
147+ [ "PREVIEW SERVER"
148+ , ""
149+ , "The preview server is not enabled in the version of Hakyll. To"
150+ , "enable it, set the flag to True and recompile Hakyll."
151+ , "Alternatively, use an external tool to serve your site directory."
152+ ]
153+#endif