on master help sign in
Add a flag to disable the preview server
1064684Jasper Van der Jeugt
.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
50 Type: git
50 Type: git
51 Location: git://github.com/jaspervdj/hakyll.git
51 Location: git://github.com/jaspervdj/hakyll.git
52
52
53+Flag previewServer
54+ Description: Include the preview server
55+ default: True
56+
53Library
57Library
54 Ghc-Options: -Wall
58 Ghc-Options: -Wall
55 Hs-Source-Dirs: src
59 Hs-Source-Dirs: src
@@ -72,8 +76,6 @@ Library
72 process >= 1.0 && < 1.4,
76 process >= 1.0 && < 1.4,
73 regex-base >= 0.93 && < 1.0,
77 regex-base >= 0.93 && < 1.0,
74 regex-pcre >= 0.93 && < 1.0,
78 regex-pcre >= 0.93 && < 1.0,
75− snap-core >= 0.5.1 && < 0.6,
76− snap-server >= 0.5.1 && < 0.6,
77 tagsoup >= 0.12 && < 0.13,
79 tagsoup >= 0.12 && < 0.13,
78 time >= 1.1 && < 1.3,
80 time >= 1.1 && < 1.3,
79 unix >= 2.4 && < 2.6
81 unix >= 2.4 && < 2.6
@@ -113,8 +115,6 @@ Library
113 Hakyll.Web.Page.Read
115 Hakyll.Web.Page.Read
114 Hakyll.Web.Pandoc
116 Hakyll.Web.Pandoc
115 Hakyll.Web.Pandoc.FileType
117 Hakyll.Web.Pandoc.FileType
116− Hakyll.Web.Preview.Poll
117− Hakyll.Web.Preview.Server
118 Hakyll.Web.RelativizeUrls
118 Hakyll.Web.RelativizeUrls
119 Hakyll.Web.Tags
119 Hakyll.Web.Tags
120 Hakyll.Web.Template
120 Hakyll.Web.Template
@@ -131,3 +131,13 @@ Library
131 Hakyll.Web.Template.Read.Hakyll
131 Hakyll.Web.Template.Read.Hakyll
132 Hakyll.Web.Template.Read.Hamlet
132 Hakyll.Web.Template.Read.Hamlet
133 Paths_hakyll
133 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 @@
1-- | Module providing the main hakyll function and command-line argument parsing
1-- | Module providing the main hakyll function and command-line argument parsing
2--
2--
3+{-# LANGUAGE CPP #-}
3module Hakyll.Main
4module Hakyll.Main
4 ( hakyll
5 ( hakyll
5 , hakyllWith
6 , hakyllWith
6 ) where
7 ) where
7
8
8−import Control.Applicative ((<$>))
9−import Control.Concurrent (forkIO)
10import Control.Monad (when)
9import Control.Monad (when)
11import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
10import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
12import System.Environment (getProgName, getArgs)
11import System.Environment (getProgName, getArgs)
13import System.Process (system)
12import System.Process (system)
14−import qualified Data.Set as S
15
13
16import Hakyll.Core.Configuration
14import Hakyll.Core.Configuration
17−import Hakyll.Core.Resource
18import Hakyll.Core.Run
15import Hakyll.Core.Run
19import Hakyll.Core.Rules
16import 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
20import Hakyll.Core.Rules.Internal
24import Hakyll.Core.Rules.Internal
21import Hakyll.Web.Preview.Poll
25import Hakyll.Web.Preview.Poll
22import Hakyll.Web.Preview.Server
26import Hakyll.Web.Preview.Server
27+#endif
23
28
24-- | This usualy is the function with which the user runs the hakyll compiler
29-- | This usualy is the function with which the user runs the hakyll compiler
25--
30--
@@ -83,11 +88,17 @@ help = do
83 , name ++ " rebuild Clean up and build again"
88 , name ++ " rebuild Clean up and build again"
84 , name ++ " server [port] Run a local test server"
89 , name ++ " server [port] Run a local test server"
85 , name ++ " deploy Upload/deploy your site"
90 , name ++ " deploy Upload/deploy your site"
91+ , ""
86 ]
92 ]
87
93
94+#ifndef PREVIEW_SERVER
95+ previewServerDisabled
96+#endif
97+
88-- | Preview the site
98-- | Preview the site
89--
99--
90preview :: HakyllConfiguration -> RulesM a -> Int -> IO ()
100preview :: HakyllConfiguration -> RulesM a -> Int -> IO ()
101+#ifdef PREVIEW_SERVER
91preview conf rules port = do
102preview conf rules port = do
92 -- Fork a thread polling for changes
103 -- Fork a thread polling for changes
93 _ <- forkIO $ previewPoll conf update
104 _ <- forkIO $ previewPoll conf update
@@ -96,6 +107,9 @@ preview conf rules port = do
96 server conf port
107 server conf port
97 where
108 where
98 update = map unResource . S.toList . rulesResources <$> run conf rules
109 update = map unResource . S.toList . rulesResources <$> run conf rules
110+#else
111+preview _ _ _ = previewServerDisabled
112+#endif
99
113
100-- | Rebuild the site
114-- | Rebuild the site
101--
115--
@@ -107,15 +121,33 @@ rebuild conf rules = do
107-- | Start a server
121-- | Start a server
108--
122--
109server :: HakyllConfiguration -> Int -> IO ()
123server :: HakyllConfiguration -> Int -> IO ()
124+#ifdef PREVIEW_SERVER
110server conf port = do
125server conf port = do
111 let destination = destinationDirectory conf
126 let destination = destinationDirectory conf
112 staticServer destination preServeHook port
127 staticServer destination preServeHook port
113 where
128 where
114 preServeHook _ = return ()
129 preServeHook _ = return ()
130+#else
131+server _ _ = previewServerDisabled
132+#endif
115
133
116−-- Upload the site
134+-- | Upload the site
117--
135--
118deploy :: HakyllConfiguration -> IO ()
136deploy :: HakyllConfiguration -> IO ()
119deploy conf = do
137deploy conf = do
120 _ <- system $ deployCommand conf
138 _ <- system $ deployCommand conf
121 return ()
139 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