on master help sign in
Add a flag to disable the preview server
commit10646840ac31b1c6e7a9b4e6d8322f321af2678b authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSat 6 Aug 2011, 19:18 (15 years ago) parent4e3238d
3 files changed+52−10
.ghci+1−1 hakyll.cabal+14−4 src/Hakyll/Main.hs+37−5
.ghci+1−1
@@ -1 +1 @@
1−:set -isrc -isrc-interval -itests -idist/build/autogen
1+:set -isrc -isrc-interval -itests -idist/build/autogen -DPREVIEW_SERVER
hakyll.cabal+14−4
@@ -50,6 +50,10 @@ Source-Repository head
5050 Type: git
5151 Location: git://github.com/jaspervdj/hakyll.git
5252
53+Flag previewServer
54+ Description: Include the preview server
55+ default: True
56+
5357Library
5458 Ghc-Options: -Wall
5559 Hs-Source-Dirs: src
@@ -72,8 +76,6 @@ Library
7276 process >= 1.0 && < 1.4,
7377 regex-base >= 0.93 && < 1.0,
7478 regex-pcre >= 0.93 && < 1.0,
75− snap-core >= 0.5.1 && < 0.6,
76− snap-server >= 0.5.1 && < 0.6,
7779 tagsoup >= 0.12 && < 0.13,
7880 time >= 1.1 && < 1.3,
7981 unix >= 2.4 && < 2.6
@@ -113,8 +115,6 @@ Library
113115 Hakyll.Web.Page.Read
114116 Hakyll.Web.Pandoc
115117 Hakyll.Web.Pandoc.FileType
116− Hakyll.Web.Preview.Poll
117− Hakyll.Web.Preview.Server
118118 Hakyll.Web.RelativizeUrls
119119 Hakyll.Web.Tags
120120 Hakyll.Web.Template
@@ -131,3 +131,13 @@ Library
131131 Hakyll.Web.Template.Read.Hakyll
132132 Hakyll.Web.Template.Read.Hamlet
133133 Paths_hakyll
134+
135+ If flag(previewServer)
136+ Build-depends:
137+ snap-core >= 0.5.1 && < 0.6,
138+ snap-server >= 0.5.1 && < 0.6
139+ Cpp-Options:
140+ -DPREVIEW_SERVER
141+ Other-Modules:
142+ Hakyll.Web.Preview.Poll
143+ Hakyll.Web.Preview.Server
src/Hakyll/Main.hs+37−5
@@ -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