Add a flag to disable the preview server
This commit is contained in:
parent
4e3238d439
commit
10646840ac
3 changed files with 52 additions and 10 deletions
2
.ghci
2
.ghci
|
@ -1 +1 @@
|
||||||
:set -isrc -isrc-interval -itests -idist/build/autogen
|
:set -isrc -isrc-interval -itests -idist/build/autogen -DPREVIEW_SERVER
|
||||||
|
|
18
hakyll.cabal
18
hakyll.cabal
|
@ -50,6 +50,10 @@ Source-Repository head
|
||||||
Type: git
|
Type: git
|
||||||
Location: git://github.com/jaspervdj/hakyll.git
|
Location: git://github.com/jaspervdj/hakyll.git
|
||||||
|
|
||||||
|
Flag previewServer
|
||||||
|
Description: Include the preview server
|
||||||
|
default: True
|
||||||
|
|
||||||
Library
|
Library
|
||||||
Ghc-Options: -Wall
|
Ghc-Options: -Wall
|
||||||
Hs-Source-Dirs: src
|
Hs-Source-Dirs: src
|
||||||
|
@ -72,8 +76,6 @@ Library
|
||||||
process >= 1.0 && < 1.4,
|
process >= 1.0 && < 1.4,
|
||||||
regex-base >= 0.93 && < 1.0,
|
regex-base >= 0.93 && < 1.0,
|
||||||
regex-pcre >= 0.93 && < 1.0,
|
regex-pcre >= 0.93 && < 1.0,
|
||||||
snap-core >= 0.5.1 && < 0.6,
|
|
||||||
snap-server >= 0.5.1 && < 0.6,
|
|
||||||
tagsoup >= 0.12 && < 0.13,
|
tagsoup >= 0.12 && < 0.13,
|
||||||
time >= 1.1 && < 1.3,
|
time >= 1.1 && < 1.3,
|
||||||
unix >= 2.4 && < 2.6
|
unix >= 2.4 && < 2.6
|
||||||
|
@ -113,8 +115,6 @@ Library
|
||||||
Hakyll.Web.Page.Read
|
Hakyll.Web.Page.Read
|
||||||
Hakyll.Web.Pandoc
|
Hakyll.Web.Pandoc
|
||||||
Hakyll.Web.Pandoc.FileType
|
Hakyll.Web.Pandoc.FileType
|
||||||
Hakyll.Web.Preview.Poll
|
|
||||||
Hakyll.Web.Preview.Server
|
|
||||||
Hakyll.Web.RelativizeUrls
|
Hakyll.Web.RelativizeUrls
|
||||||
Hakyll.Web.Tags
|
Hakyll.Web.Tags
|
||||||
Hakyll.Web.Template
|
Hakyll.Web.Template
|
||||||
|
@ -131,3 +131,13 @@ Library
|
||||||
Hakyll.Web.Template.Read.Hakyll
|
Hakyll.Web.Template.Read.Hakyll
|
||||||
Hakyll.Web.Template.Read.Hamlet
|
Hakyll.Web.Template.Read.Hamlet
|
||||||
Paths_hakyll
|
Paths_hakyll
|
||||||
|
|
||||||
|
If flag(previewServer)
|
||||||
|
Build-depends:
|
||||||
|
snap-core >= 0.5.1 && < 0.6,
|
||||||
|
snap-server >= 0.5.1 && < 0.6
|
||||||
|
Cpp-Options:
|
||||||
|
-DPREVIEW_SERVER
|
||||||
|
Other-Modules:
|
||||||
|
Hakyll.Web.Preview.Poll
|
||||||
|
Hakyll.Web.Preview.Server
|
||||||
|
|
|
@ -1,25 +1,30 @@
|
||||||
-- | Module providing the main hakyll function and command-line argument parsing
|
-- | Module providing the main hakyll function and command-line argument parsing
|
||||||
--
|
--
|
||||||
|
{-# LANGUAGE CPP #-}
|
||||||
module Hakyll.Main
|
module Hakyll.Main
|
||||||
( hakyll
|
( hakyll
|
||||||
, hakyllWith
|
, hakyllWith
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Applicative ((<$>))
|
|
||||||
import Control.Concurrent (forkIO)
|
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
|
import System.Directory (doesDirectoryExist, removeDirectoryRecursive)
|
||||||
import System.Environment (getProgName, getArgs)
|
import System.Environment (getProgName, getArgs)
|
||||||
import System.Process (system)
|
import System.Process (system)
|
||||||
import qualified Data.Set as S
|
|
||||||
|
|
||||||
import Hakyll.Core.Configuration
|
import Hakyll.Core.Configuration
|
||||||
import Hakyll.Core.Resource
|
|
||||||
import Hakyll.Core.Run
|
import Hakyll.Core.Run
|
||||||
import Hakyll.Core.Rules
|
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.Core.Rules.Internal
|
||||||
import Hakyll.Web.Preview.Poll
|
import Hakyll.Web.Preview.Poll
|
||||||
import Hakyll.Web.Preview.Server
|
import Hakyll.Web.Preview.Server
|
||||||
|
#endif
|
||||||
|
|
||||||
-- | This usualy is the function with which the user runs the hakyll compiler
|
-- | 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 ++ " rebuild Clean up and build again"
|
||||||
, name ++ " server [port] Run a local test server"
|
, name ++ " server [port] Run a local test server"
|
||||||
, name ++ " deploy Upload/deploy your site"
|
, name ++ " deploy Upload/deploy your site"
|
||||||
|
, ""
|
||||||
]
|
]
|
||||||
|
|
||||||
|
#ifndef PREVIEW_SERVER
|
||||||
|
previewServerDisabled
|
||||||
|
#endif
|
||||||
|
|
||||||
-- | Preview the site
|
-- | Preview the site
|
||||||
--
|
--
|
||||||
preview :: HakyllConfiguration -> RulesM a -> Int -> IO ()
|
preview :: HakyllConfiguration -> RulesM a -> Int -> IO ()
|
||||||
|
#ifdef PREVIEW_SERVER
|
||||||
preview conf rules port = do
|
preview conf rules port = do
|
||||||
-- Fork a thread polling for changes
|
-- Fork a thread polling for changes
|
||||||
_ <- forkIO $ previewPoll conf update
|
_ <- forkIO $ previewPoll conf update
|
||||||
|
@ -96,6 +107,9 @@ preview conf rules port = do
|
||||||
server conf port
|
server conf port
|
||||||
where
|
where
|
||||||
update = map unResource . S.toList . rulesResources <$> run conf rules
|
update = map unResource . S.toList . rulesResources <$> run conf rules
|
||||||
|
#else
|
||||||
|
preview _ _ _ = previewServerDisabled
|
||||||
|
#endif
|
||||||
|
|
||||||
-- | Rebuild the site
|
-- | Rebuild the site
|
||||||
--
|
--
|
||||||
|
@ -107,15 +121,33 @@ rebuild conf rules = do
|
||||||
-- | Start a server
|
-- | Start a server
|
||||||
--
|
--
|
||||||
server :: HakyllConfiguration -> Int -> IO ()
|
server :: HakyllConfiguration -> Int -> IO ()
|
||||||
|
#ifdef PREVIEW_SERVER
|
||||||
server conf port = do
|
server conf port = do
|
||||||
let destination = destinationDirectory conf
|
let destination = destinationDirectory conf
|
||||||
staticServer destination preServeHook port
|
staticServer destination preServeHook port
|
||||||
where
|
where
|
||||||
preServeHook _ = return ()
|
preServeHook _ = return ()
|
||||||
|
#else
|
||||||
|
server _ _ = previewServerDisabled
|
||||||
|
#endif
|
||||||
|
|
||||||
-- Upload the site
|
-- | Upload the site
|
||||||
--
|
--
|
||||||
deploy :: HakyllConfiguration -> IO ()
|
deploy :: HakyllConfiguration -> IO ()
|
||||||
deploy conf = do
|
deploy conf = do
|
||||||
_ <- system $ deployCommand conf
|
_ <- system $ deployCommand conf
|
||||||
return ()
|
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
|
||||||
|
|
Loading…
Reference in a new issue